Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrade Hibernate version in JBOSS

I am having a hard time when trying to ship inside my EAR my own version of Hibernate (and not the one that JBoss brings by default).

Then I made my deployment "scoped" by including in the EAR a jboss-app.xml file containing the following:

<jboss-app>
  <loader-repository> 
  com.example:archive=unique-archive-name 
     <loader-repository-config> 
     java2ParentDelegation=false 
     </loader-repository-config> 
  </loader-repository>
</jboss-app>

And, as usual, I declare my persistence provider in the persistence unit to be Hibernate, as follows:

<persistence>
   <persistence-unit name="myapp">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
   ...

But then, the worst happens. On deployment, the server throws a ClassCastException when it tries to cast from org.hibernate.ejb.HibernatePersistence to the JPA interface javax.persistence.spi.PersistenceProvider (which IS implimented by HibernatePersistence).

This is kind of WEIRD, because I am shipping the JPA API also in my EAR, so, given that the classes of the EAR have priority to those of JBoss, it should have no problem when casting from HibernatePersistence to PersistenceProvider, since they "should be" on the same class loader.

If I don't ship my own JPA API, then the deployment fails with a ClassNotFoundException when JBoss tries to find some JPA class.

Any idea on why is this casting failing?

I am using JBoss 5.1.0, and trying to use Hibernate 3.5.6.Final. The JPA API version is the one imported transitively by the menctioned Hibernate version.

like image 322
Mr.Eddart Avatar asked Oct 11 '22 02:10

Mr.Eddart


1 Answers

You could try turning on class scoping via the ear deployer. For JBoss 5.x edit:

jboss/server/[configuration]/deployers/ear-deployer-jboss-beans.xml

and change:

   <bean name="EARClassLoaderDeployer" class="org.jboss.deployment.EarClassLoaderDeployer">
      <property name="isolated">false</property>
   </bean>

setting isolated to true.

like image 109
Tim Avatar answered Oct 20 '22 00:10

Tim