8

I have found out that "Hibernate cannot be combined with the reference implementation of JAX-RS." on the link http://lists.jboss.org/pipermail/hibernate-issues/2009-May/015628.html

So i am unable to combine JAX-RS (jersey) with hibernate, does anybody know a work around for this ?

  • Did you ever find a resolution to this? I am running into this right now. I am using Hibernate 3.2 Core, Annotations, and Entity Manager. Hibernate dies when I try to add JAX-RS libraries. Thanks. – kmehta Mar 03 '11 at 23:08

4 Answers4

13

The root of evil is cglib. Substitute cglib-2.1.3.jar to cglib-nodep-2.1_3.jar and delete hibernate's asm*.jar files.

FoxyBOA
  • 5,788
  • 8
  • 48
  • 82
  • not working for me... getting `java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor` – aps109 May 18 '14 at 08:23
5

Using Jersey (the Java REST framework) in conjunction with Hibernate requires some tweaking of Maven's pom.xml file. The issue is that Hibernate uses ASM 1.5.3 which is incompatible with ASM 3.1 used by Jersey.

What you need to do is exclude some transitive dependencies from Hibernate:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate</artifactId>
    <version>3.2.6.ga</version>
    <exclusions>
        <exclusion>
            <groupId>asm</groupId>
            <artifactId>asm</artifactId>
        </exclusion>
        <exclusion>
            <groupId>asm</groupId>
            <artifactId>asm-attrs</artifactId>
        </exclusion>
        <exclusion>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Then, you need to include the correct version of ASM:

<dependency>
    <groupId>asm</groupId>
    <artifactId>asm</artifactId>
    <version>3.1</version>
</dependency>

Finally, you need to include a nodep version of the CGLib which repackages classes from ASM version 1.5.3:

<dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib-nodep</artifactId>
    <version>2.1_3</version>
</dependency>

source: http://blog.idm.fr/2009/04/jersey-hibernate-conflict.html

mychalvlcek
  • 3,956
  • 1
  • 19
  • 34
3

SOLUTION: Compatibility Issue of ASM 3.1 and HIbernate and JAX-RS

  • Remove the following jars
    1 asm-attrs.jar
    2 asm.jar
    3 cglib-2.1.3.jar

  • Add the below jar

1 asm-3.1.jar
2 cglib-nodep-2.1_3.jar

Anurag
  • 41
  • 3
3

Upgrade to a Hibernate 3.3.2 or later.

If you follow the link to the bug report that message was generated from, it indicates that the latest versions of Hibernate (since 3.3.2) use a different bytecode manipulation package (Javassist), which eliminates the conflict over ASM which caused the problem.

Chadwick
  • 12,555
  • 7
  • 49
  • 66
  • 1
    HIbernate 3.3.2 didnt help, i think we still need to instruct hibernate to use javassist in hibernate.properties file, where my project uses hibernate.cfg.xml file, and we cannot enforce javassist in xml file. –  Jun 10 '09 at 05:38