Saturday, November 16, 2013

Add Hibernate 3 to JBoss AS 7 JBoss EAP 6 Migrate Hibernate 3 to JBoss 7 JBoss eap6

Removed
JBoss comes with Hibernate 4 jars. The Hibernate Module is located in

C:\jboss-eap-6.1\modules\system\layers\base\org\hibernate\main

Jboss adds Hibernate if he detects the presence of an @PersistenceUnit, @PersistenceContext annotation, or a <persistence-unit-ref> or <persistence-context-ref> . So we don't need to declare dependency in the jboss-deployment-structure.xml.

But in my case, my application is using Hibernate 3.3, so I have errors in my Hibernate imports as Hibernate 3 differs from Hibernate 4. What to doooooo.


Ok, as I would like to use Hibernate 3 in different application, I prefer to create a new module in JBoss. But this time it will be easier as I have a Hibernate in my modules. So let's start:

Step1:

Create a folder named 3 under "C:\jboss-eap-6.1\modules\system\layers\base\org\hibernate\"



Step2:

Working with Hibernate 3.3, I have downloaded it and put it in the directory 3 with the file module.xml. But I have an error :

javax.persistence.PersistenceException: JBAS011466: PersistenceProvider 'org.hibernate.ejb.HibernatePersistence' not found


In fact 'org.hibernate.ejb.HibernatePersistence' don’t exists at all in Hibernate 3.3, I have upgrated the application to use Hibernate3.6 and the error disappeared. So my hibernate/3 directory looks like this :


And my module.xml associated is this one:


There is no need to add anything to jboss-dependency-structure.xml as it will be loaded implicitely.

Step3: 

Make changes in the persistence.xml

In fact you should delete the provider from persistence.xml, which was org.hibernate.ejb.HibernatePersistence and add this line.

<property name="jboss.as.jpa.providerModule" value="org.hibernate:3" />

The persistence.xml looks like this :




2 comments :

  1. The Session was the entry point for hibernate3. Session was obtained using JNDI lookup in earlier JBoss version. When using persistence.xml with EAP6, how did you get Session object? JNDI lookup or dependency injection?

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete

Articles les plus consultés