I am using hibernate in my code, and running my app on jboss 4.0.5GA. The supplied jboss hibernate library doesn't include the entity manager, which I need. Even though I've included hibernate 3.6.0 in my application's lib directory, it's not found at startup.
java.lang.NoClassDefFoundError: org/hibernate/cfg/ExtendedMappings at org.hibernate.ejb.Ejb3Configuration.(Ejb3Configuration.java:129) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:55) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) ........ Caused by: java.lang.ClassNotFoundException: Unexpected error during load of: org.hibernate.cfg.ExtendedMappings, msg=Implementing class at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:550) at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:405) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ... 142 more Caused by: java.lang.IncompatibleClassChangeError: Implementing class
I think this is because the hibernate core library from jboss is loaded before the hibernate 3.6 libs supplied with the app.
The problem is I can't change any jar files under JBOSS_HOME. I can change / provide various bits of jboss config since we set the domain directory to the application home, so for example we supply a jboss/conf/jboss-service.xml and I can tweak that.
I've tried a few ways to fix this, and here's what I've found:
If I remove the hibernate3.jar from JBOSS_HOME/server/default/lib the problem is fixed
If I replace JBOSS_HOME/server/default/lib/hibernate3.jar with the correct version (3.6.0) that also fixes it
There's another approach I tried: given that jboss supplies a hibernate core (version 3.2) but not the entity manager or annotations, I tried supplying the entity manager & annotation libs for that same version of hibernate (3.2.0GA) in my app. However this caused a
java.lang.IllegalAccessError: tried to access method org.hibernate.cfg.Mappingsbecause (I think) the jar files were being loaded by different classloaders / from different repositories. According to this post all hibernate libs need to be loaded from the same place. Not possible in my case.
I also tried playing with the ear-deployer.xml to switch on isolated classloading. That opened a whole Pandora's box of exceptions which I don't think I can fix.
Help!