简体   繁体   中英

java.lang.AbstractMethodError after upgrading to Hibernate 3.3.2

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.

引发错误的瞬间进行堆栈跟踪

The application is running on JBoss 5.1.0 .

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

EDITED

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!

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