users@glassfish.java.net

Glassfish and Hibernate v3 as the JPA provider packaged in an EAR - notes.

From: <glassfish_at_javadesktop.org>
Date: Mon, 17 Mar 2008 22:36:28 PST

I've been banging my head trying to get Glassfish to use Hibernate 3 as my JPA provider packaged within my EAR file instead of TopLink essentials. Finally got it to work, just a few tips for other people trying to do the same thing..

GlassFish Version = V2 UR1
Hibernate v3 Core Version = 3.2.6.ga
Hibernate EntityManager Version = 3.2.2.ga

My ear file is packaged as such

MyEAR.ear [
 lib\
 lib\hibernate3.jar
 lib\hibernate-annotations.jar
 lib\hibernate-commons-annotations.jar
 lib\hibernate-entity-manager.jar
 lib\antlr-2.7.6.jar
 lib\asm.jar
 lib\asm-attrs.jar
 lib\commons-collections-2.1.1.jar
 lib\commons-logging-1.0.4.jar
 lib\concurrent-1.3.2.jar
 lib\dom4j-1.6.1.jar
 lib\ehcache-1.2.3.jar
 lib\javassist.jar
 lib\log4j-1.2.11.jar
 MyModel.jar (Java Persistence Unit)
 MyEJB.jar (EJB Session Beans)
 MyWebApp.war (Web Application)
]

In regards to the MyModel.jar - it includes the POJO classes, along with the META-INF/orm.xml, and the META-INF/persistence.xml.

The persistence.xml will require that the JPA provider be set as such

<provider>org.hibernate.ejb.HibernatePersistence</provider>

Moreover, the following hibernate properties will also need to be set (in the persistence.xml)

<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider" />
<property name="hibernate.cache.use_query_cache" value="true" />
<property name="hibernate.max_fetch_depth " value="3" />
<property name="hibernate.default_batch_fetch_size" value="16" />
<property name="hibernate.order_updates" value="true" />
<property name="hibernate.order_inserts" value="true" />

[b]
It is also very important to create a "hibernate.properties" file inside the MyModel.jar[/b]. If you try setting this in your persistence.xml - your PU will just fail to deploy as it will still default to CGLIB (using cglib will just give you class loading errors even if you have the cglib-2.1.3 in your EAR's lib folder - the exceptions throw will be some ClassNotFoundException). So basically, make sure you create a hibernate.properties file with the following content

hibernate.bytecode.provider=javassist
[Message sent by forum member 'gdaswani' (gdaswani)]

http://forums.java.net/jive/thread.jspa?messageID=264527