Rajeswari Kotikalapudi
Rajeswari Kotikalapudi

Reputation: 592

Hibernate and Jersey conflicts using Tomcat and Eclipse IDE

In my project I am using both Hibernate & Jersey there is a library conflict with Hibernate, Jersey from the below link I getting like this

http://www.hildeberto.com/2008/05/hibernate-and-jersey-conflict-on.html

Jersey uses the ASM library, which is also used by Hibernate, but on different versions. Hibernate uses version 1.5.3 and Jersey uses 3.5.1. A big difference! We can not just delete the old version and put the new one there because they are architecturally different. Version 1.5.3 has an "attrs" package while 3.5.1 doesn't have it but a "signatures" package. The ASM package is needed by the cglib package, which is part of the Hibernate libraries. If we remove that package, Jersey will work correctly, but Hibernate will stop working. To solve this conflict use cglib-nodep.jar instead of cglib.jar and keep ASM version 3.x with Jersey. cglib-nodep.jar includes some ASM classes demanded by cglib.jar, changing the package name to avoid any class conflict.

but after including the asm-3.1.jar, asm-attrs-2.2.3.jar, asm-commons-3.1.jar, asm-util-3.1.jar, cglib-nodep-2.1_3sources.jar I am getting errors:

if I place cglib 2.1.3:

java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(Z)V
    at net.sf.cglib.core.DebuggingClassWriter.<init>(DebuggingClassWriter.java:47)
    at net.sf.cglib.core.DefaultGeneratorStrategy.getClassWriter(DefaultGeneratorStrategy.java:30)

if I place cglib-nodep-2.1_3-sources.jar:

java.lang.ClassNotFoundException: net.sf.cglib.core.KeyFactory
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1701)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)

please any one list the jar files need to resolve this issue.

Upvotes: 1

Views: 1461

Answers (1)

Kevin Welker
Kevin Welker

Reputation: 7937

If I'm not mistaken, cglib is no longer the preferred bytecode provider for Hibernate. Rather Javassist is and you can force Javassist with the following:

hibernate.bytecode.provider=javassist

In recent versions of Hibernate, this is already the default behavior. You must either have an older version of Hibernate, or the project is already being configured to override the above with cglib. So you can either update your version of Hibernate, or configure your instance to use javassist instead. Configuration kind of depends on your environment and what you want. In general, you include the above line in a hibernate.properties file in your classpath. I think you can also add -Dhibernate.bytecode.provider=javassist to command line or in JAVA_OPTS for JBoss configuration.

You can see more discussion here and elsewhere on the web. Just Google hibernate.bytecode.provider

Upvotes: 2

Related Questions