0

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.Mappings
because (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!

skaffman
  • 398,947
  • 96
  • 818
  • 769
mdarwin
  • 1,684
  • 7
  • 28
  • 72
  • Interestingly, if I prepend the jboss start classpath with the path to my hibernate jar (a dirty hack if ever there was one), I get the following exception:java.lang.NoClassDefFoundError: javax/persistence/spi/PersistenceProvider Caused by: java.lang.ClassNotFoundException: javax.persistence.spi.PersistenceProvider – mdarwin Jan 26 '12 at 14:26
  • See http://stackoverflow.com/questions/1157313/jboss-scoped-class-loading – skaffman Jan 26 '12 at 16:35

0 Answers0