我在各种网站上发现了一些似乎触及这个问题的线程,但我没有运气.似乎根本无法完成.我明白了
引起:java.lang.IncompatibleClassChangeError:找到接口org.hibernate.cfg.Mappings,但是类是预期的错误.看看compatability matrix compatability matrix ,似乎除非我降级,否则我不能使用.但这似乎不对.
当我开始升级所有工作,现在我得到同样的错误.我确保在课程路径上没有两个不同的同名的罐子.我有以下罐子:
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..
这是完整的堆栈跟踪:
...
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)
...
蚂蚁:
<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>
任何帮助都会很棒;这台电脑即将被抛出.多谢你们.
解决方法:
根据这个link. Max,hibernate的一个贡献者,状态(靠近线程的底部):
“问题是Hibernate 3.6具有从类到接口的类更改,这意味着它与源代码兼容,但与Hibernate Tools不兼容.
加上其他二进制更改会导致此问题并记录在https://issues.jboss.org/browse/JBIDE-8071中
因此,“解决方法”是当您需要使用hibernate工具生成代码,然后在类路径中不包含hibernate 3.6时;之后的代码可以很好地使用3.6.
挑战在于,如果我们增加3.6支持,我们也会放弃3.3-3.5支持.
因此,目前我们还没有更新,但会尝试看看我们可以做些什么.“
看来我试图做不可能的事.虽然我很高兴我终于有了答案,但我遗憾地说这不是我希望的答案.
一个人不能在同一个类路径上拥有两个jar,即使它们彼此依赖.如果你想对一些hibernate代码进行逆向工程,最好没有hibernate 3.6版本!