Search code examples
javaspringhibernatehibernate3

Upgrade to Hibernate 3.6 errors with reverse engineering


I have found a few threads on various sites that seem to touch on this problem, but I am having no luck. It seems as though it simply can not be done. I get the Caused by: java.lang.IncompatibleClassChangeError: Found interface org.hibernate.cfg.Mappings, but class was expected error. Looking at the compatability matrix that is Shown in this thread. it seems that I can't use reveng unless I downgrade. But this can not seem right.

When I started upgrading everything worked, and now I am getting that same error. I made sure not to have two different jars with the same name on my class path. I have the following jars:

commons-logging-1.0.4.jar
dom4j-1.6.1.jar
hibernate3.jar
hibernate-tools.jar    
slf4j-api-1.6.6.jar
slf4j-log4j12-1.6.6.jar
sqljdbc4.jar
other various jars not dealing with hibernate..

Here is the full stack trace:

    ...   
    hibernatetool
    Executing Hibernate Tool with a JDBC Configuration (for reverse engineering)
    1. task: hbm2hbmxml (Generates a set of hbm.xml files)     java.lang.IncompatibleClassChangeError: Found interface org.hibernate.cfg.Mappings, but class was expected
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:116)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:390)
    at org.apache.tools.ant.Target.performTasks(Target.java:411)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.apache.tools.ant.Main.runBuild(Main.java:809)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:29)
Caused by: java.lang.IncompatibleClassChangeError: Found interface org.hibernate.cfg.Mappings, but class was expected
    at org.hibernate.cfg.reveng.MappingsDatabaseCollector.getTable(MappingsDatabaseCollector.java:25)
    at org.hibernate.cfg.reveng.JDBCReader.processTables(JDBCReader.java:535)
    at org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:74)
    at org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:860)
    at org.hibernate.cfg.JDBCBinder.readDatabaseSchema(JDBCBinder.java:121)
    at org.hibernate.cfg.JDBCBinder.readFromDatabase(JDBCBinder.java:94)
    ... 

ant:

<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="classpath" />
...
 <hibernatetool>
    <jdbcconfiguration configurationfile="${conf.dir}/${dbName}_hibernate-template.cfg.xml" packagename="myPackageName" revengfile="${conf.dir}/hibernate.reveng.xml" reversestrategy="com.capitaliq.loader.dev.codegen.HibernateReverseStrategy" detectmanytomany="false" />
    <hbm2hbmxml destdir="${srcGen.dir}" />
    <!-- Generate new hibernate.cfg.xml including new POJOs-->
    <!--'destdir' is relative to 'packagename' configuration-->
    <hbm2cfgxml ejb3="false" destdir="${conf.dir}" />
</hibernatetool>

<!-- Generate java POJOs from mapping files-->
<hibernatetool> <!--Line 384-->
    <configuration configurationfile="${conf.dir}/${dbName}_hibernate-template.cfg.xml">
        <fileset dir="${orm.pkg.dir}">
            <include name="**/*.hbm.xml" />
        </fileset>
    </configuration>
    <!--'destdir' is relative to 'packagename' configuration-->
    <hbm2java jdk5="true" ejb3="false" destdir="${srcGen.dir}" />
</hibernatetool>

Any help would be great; this computer is about to get thrown. Thanks guys.


Solution

  • According to this link. Max, one of the contributors to hibernate, states (near the bottom of the thread):

    "The problem is that Hibernate 3.6 has a class change from class to interface which means it is source compatible but not binary compatible with Hibernate Tools.

    That plus other binary changes causes this problem and is recorded in https://issues.jboss.org/browse/JBIDE-8071

    Thus the "workaround" is when you need to generate code with hibernate tools then don't include hibernate 3.6 on the classpath; the resulting code can be used fine with 3.6 afterwards.

    The challenge is that if we added 3.6 support we would loose 3.3-3.5 support too. Thus for now we are not updating but will try and see what we can do going forward."

    It appears I was trying to do the impossible. Though I am glad I finally have an answer, I regret to say it is not the one I hoped it would be.

    One can not have the two jars on the same classpath, even though the are dependent on one another. If you want to reverse engineer some hibernate code, best not have hibernate version 3.6!