0

We have a legacy application that uses Hibernate 3.0.5 and we're trying to upgrade it to Hibernate 3.3.2 (the version that has less impact on the current code).

After updating the dependencies in pom.xml, the application deploys correctly, but on queries where there's a lazy association, the following error occurs:

java.lang.AbstractMethodError: org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.setUnwrap(Z)V

The dependencies are configured as follow:

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-core</artifactId>
  <version>3.3.2.GA</version>
  <exclusions>
    <!-- 
      Excludes to avoid conflict with JBoss libs
      See http://stackoverflow.com/questions/3413488/saxparser-errors-with-hibernate-and-jboss-conflicting-versions
     -->
    <exclusion>
      <groupId>xml-apis</groupId>
      <artifactId>xml-apis</artifactId>
      <version>1.0.b2</version>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-simple</artifactId>
  <version>1.5.2</version>
</dependency>
<dependency>
  <groupId>javassist</groupId>
  <artifactId>javassist</artifactId>
  <version>3.4.GA</version>
</dependency>
<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.14</version>
</dependency>

We've already tried to switch do CGLIB instead of Javassist, but we receive the same error on the equivalent class (org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer). There is no stack trace. Here is a picture of the execution stack in the moment the error is thrown.

Stack trace in the moment the error is thrown

The application is running on JBoss 5.1.0.

Any tips about this error? Could this be the wrong version of javassist library?

EDITED

Joaquim Oliveira
  • 1,208
  • 2
  • 16
  • 29
  • Are you using JBoss? If not, what app server? I've seen this issue before (mostly with JBoss) but I'd be interested in knowing that before offering any specific guidance. – J Steven Perry Feb 18 '14 at 22:02
  • Is that the "full" error message? `java.lang.AbstractMethodError: org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.setUnwrap(Z)V ` – Peter Svensson Feb 18 '14 at 22:07
  • @JStevenPerry, added JBoss version on the question. – Joaquim Oliveira Feb 19 '14 at 15:02
  • I guess it is caused by conflicting ASM jars, CGLIB depends on ASM. Workaround for CGLIB is a spacial cglib-nodep.jar, it includes correct ASM version with renamed packages. – jbaliuka Feb 19 '14 at 15:04
  • @jabliuka, `ASM` and `CGLIB` are not included as dependencies. Moreover, according to [this migration guide](https://community.jboss.org/wiki/HibernateCoreMigrationGuide33) Hibernate 3.3 default is now `javassist` – Joaquim Oliveira Feb 20 '14 at 18:04

1 Answers1

0

I ran into an issue very similar to this one, and it turned out to be a JBoss Class Loader issue. JBoss configurations change quickly from one version to the next, and the solution I'm proposing worked for me using JBoss EAP 5.1.2.

Here goes.

First, make sure to explicitly include the version of Hibernate in your POM:

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-core</artifactId>
  <version>3.3.2.GA</version>
</dependency>

Next, you will want to override JBoss' default ClassLoader isolation by including a file called jboss-web.xml in your WEB-INF folder of your WAR file (this same approach should also work if you are deploying an EAR). Its format looks like:

<jboss-web>
  <class-loading>
    <loader-repository>
        org.hibernate=my-application.war
        <loader-repository-config>java2ParentDelegation=false</loader-repository-config>
    </loader-repository>
  </class-loading>
</jboss-web>

Where my-application.war is the name of your WAR file. Note that the java2ParentDelegation set to false may help with other ClassLoader issues (especially with slf4j in my experience).

Finally, JBoss 5.1.x ClassLoader issues are maddening to deal with, so I hope this helps. The thing to keep in mind is that the problem is not related to javassist per se (and you may consider removing the explicit javassist <dependency> in your POM and let Maven resolve it based on the Hibernate <dependency>). This is most likely a ClassLoader issue. And the default JBoss strategy for ClassLoading works great most of the time, until you get Hibernate involved. JBoss pre-Version 6 is deeply tied to the specific version of Hibernate that ships with JBoss, so trying to use a different version of Hibernate than the one JBoss wants to use is a real pain. But it can be done!

For EAR files, the file is called jboss-app.xml and goes in the META-INF folder of your EAR file:

<jboss-app>
  <loader-repository> 
  org.hibernate:archive=my-application.ear 
     <loader-repository-config> 
     java2ParentDelegation=false 
     </loader-repository-config> 
  </loader-repository>
</jboss-app>

Good luck!

J Steven Perry
  • 1,711
  • 1
  • 17
  • 28
  • The error continues despite the configuration. I enabled JBoss classloading log and the JARs being used (javassist, hibernate-core) are (apparently) those in WEB-INF/lib. – Joaquim Oliveira Feb 20 '14 at 17:58
  • I'm not completely sure what you're saying. Can you clarify? The JARs are in `WEB-INF/lib` but the `jboss-web.xml` file needs to go in `WEB-INF`. – J Steven Perry Feb 20 '14 at 18:44
  • Sorry, I mixed two answers in one sentence. I did the configuration you suggested in `jboss-web.xml` and also removed explicit `javassist` dependency in `pom.xml`, but it didn't work. So I noticed a `javassist.jar` in `$JBOSS_HOME/lib`, and I thought it was not being loaded (because it was configured to not load from parent) and declared it explicitly in POM. The log confirmed the jar was being read from `WEB-INF/lib` but I got the same error message. – Joaquim Oliveira Feb 20 '14 at 19:02
  • Bummer. JBoss class loading in EAP 5.1 is absolutely hellish. Sorry my suggestion didn't work for you. – J Steven Perry Feb 20 '14 at 19:22
  • The strangest thing is that version 3.3.1 that ships with JBoss works nicely. Thanks anyway for your help! – Joaquim Oliveira Feb 21 '14 at 13:06