views:

88

answers:

3

I'm using Hibernate 3.5.0, JBoss AS 6 and Liquibase 1.9.5.

I wanted to activate EhCache Hibernate second-level caching as follows:

The first thing I do, is adding a new dependency to the pom.xml:

 <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-ehcache</artifactId>
            <version>3.5.0-Final</version>
 </dependency>

Now, when I redeploy my app, following Exception is thrown:

Caused by: java.lang.VerifyError: (class: liquibase/database/HibernateDatabase, method: <init> signature: (Ljava/lang/String;)V) Bad type in putfield/putstatic
        at java.lang.Class.getDeclaredMethods0(Native Method) [:1.6.0_18]
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2427) [:1.6.0_18]
        at java.lang.Class.getDeclaredMethods(Class.java:1791) [:1.6.0_18]
        at org.jboss.deployment.AnnotatedClassFilter.hasAnnotations(AnnotatedClassFilter.java:186) [:6.0.0.20100429-M3]
        at org.jboss.deployment.AnnotatedClassFilter.accepts(AnnotatedClassFilter.java:114) [:6.0.0.20100429-M3]
        at org.jboss.deployment.AnnotatedClassFilter.visit(AnnotatedClassFilter.java:99) [:6.0.0.20100429-M3]
        at org.jboss.vfs.VirtualFile.visit(VirtualFile.java:407) [jboss-vfs.jar:3.0.0.CR5]
        at org.jboss.vfs.VirtualFile.visit(VirtualFile.java:409) [jboss-vfs.jar:3.0.0.CR5]
        ...

Note that I didn't activate the caching in persistence.xml yet (!)

Does this ring a bell to somebody? Any clues are more than welcome.

Thank you!

+1  A: 

Is there any other "Caused by" messages later on?

I could be that liquibase is built against an earlier version of hibernate than you are running and the hibernate API has changed. Did you just add the ehcache dependency? Or did hibernate get upgraded as well?

Nathan Voxland
Thank you for the reply Nathan. Found the solution in the mean time. (See infra.) A version mismatch indeed. Definitely not Liquibase's fault ;-)
Jan
+1  A: 

Looks like a version mismatch.

Actually, EhCache 2.2 seems to fit my configuration better. (Hibernate 3.5.0 & JBoss AS 6 (and Liquibase 1.9.5)):

Add to persistence.xml:

    <property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.EhCacheRegionFactory"/>

Add to pom.xml:

<dependency>
    <groupId>net.sf.ehcache</groupId>
    <artifactId>ehcache-core</artifactId>
    <version>2.2.0</version>
</dependency>

(This Maven dependency does not explicitely depend on "Hibernate", which keeps the dependency hierachy a bit cleaner.)

Jan
Actually, this is just another way. Here you're using EhCache 2.x and the cache provider implementation *from EhCache*. But using EhCache 1.5.0 and the cache provider implementation *from Hibernate* is not wrong and it should work. In my opinion, the problem is still there, it's just hidden.
Pascal Thivent
Better wording IMO, +1 :)
Pascal Thivent
A: 

The artifact hibernate-ehcache doesn't add any particular Hibernate artifact so I'm not sure it's really the root cause of the problem. However, maybe you changed the classpath order (by declaring it before liquidbase) and you revealed the problem. You can maybe try to declare it after (in the pom.xml).

You could also try to run the JVM with -Xverify:all to see if you get a more useful message.

Or, recompile liquibase against Hibernate 3.5.x.

Pascal Thivent
@Pascal: Thank you for clarifying the difference between ehcache 1.x and 2.x. What I observe:"hibernate-ehcache:jar:3.5.0-Final" pulls in the full (!) "hibernate-core:jar:3.5.0-Final" and "ehcache:jar:1.5.0". On the other hand, "ehcache-core:jar:2.2.0" has no further mvn dependencies. I'm pretty sure these additional dependencies mix up with the ones already 'provided' in JBoss. I know I could exclude them again from the pom, but that gets very messy as well. I think the 2.2 version of ehcache suits this situation better.
Jan
@Jan That seems to be a very plausible explanation indeed. Anyway, you have a working solution, that's cool, I just wanted to clarify the difference and that using EhCache 1.5 was not wrong, just different :)
Pascal Thivent