简体   繁体   中英

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.

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.

Have you included the hibernate-entitymanager.jar too?

Otherwise you can try replacing the hibernate core jar in the common/lib with the 3.5.6 version.

To solve the class loading issues with hibernate in jboss server you need to add the jboss-classloading.xml inside the WEB-INF folder of your web application. Read more about these configuration settings here .

<classloading xmlns="urn:jboss:classloading:1.0"
domain="pentaho.ear"
export-all="NON_EMPTY"
import-all="true"
parent-first="false">
</classloading>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM