使用Eclipse的hibernate插件进行工程反转生成po类Could not initialize class org.hibernate.cfg.reveng.OverrideReposity

来源:互联网 发布:淘宝客优惠券网站建站 编辑:程序博客网 时间:2024/06/05 10:45

hibernate插件是适合Eclipse版本的最新版本,工程反转使用的hibernate3.6
使用Eclipse的hibernate插件进行工程反转生成po类时报错:

org.hibernate.console.HibernateConsoleRuntimeException: Received a NoClassDefFoundError, probably the console configuration classpath is incomplete or contains conflicting versions of the same classReceived a NoClassDefFoundError, probably the console configuration classpath is incomplete or contains conflicting versions of the same class  java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.cfg.reveng.OverrideRepository  Could not initialize class org.hibernate.cfg.reveng.OverrideRepository    java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.cfg.reveng.OverrideRepository    Could not initialize class org.hibernate.cfg.reveng.OverrideRepository

查了很多资料,有人说是jar包冲突,但是这里设置了buildpath(只将hibernate3.jar,jdbc驱动,hibernate方言包加入buildpath中),删除了所有可能冲突的jar包问题仍问解决。
最终发现问题出在设置的hibernate.reveng.xml文件。
如果不设置reveng.xml文件,则文件找不到的问题消失,改成出现如下问题。

org.hibernate.cfg.JDBCBinderException: Duplicate class name com.pepspb.entity.CheckConstraints generated for org.hibernate.mapping.Table(test.student). Same name where generated for org.hibernate.mapping.Table(test.student)Duplicate class name 'com.pepspb.entity.CheckConstraints generated for org.hibernate.mapping.Tabletest.student). Same name where generated for org.hibernate.mapping.Table(test.student)<No message>

这个问题是由于数据库中存在多个模式中有相同的表
查看数据库连接,显示设置的连接下不仅包含我们需要的模式Militaryms_v2,还包括其他模式,而其模式中存在与该模式相同的表名。
hibernate.reveng.xml就是用来配置工程反转的表和模式,这里没有设置该文件,所以会发现同名的表。

解决方法一:不添加hibernate.reveng.xml文件,数据库中不同模式下设置成不同表名。

解决方法二:配置buildpath,换成hibernate3.5.jar包(hibernate3.5可以正常生成hibernate.reveng.xml文件),jdbc驱动以及相应的方言包。

hibernate.reveng.xml文件:<hibernate-reverse-engineering>  < table-filter match-name= "asroc"/>  //如果数据库中不同模式下有相同表名,那么不设置模式会出现上述类名重复问题</hibernate-reverse-engineering>

hibernate3.5版本生成hibernate.reveng.xml文件正常,可以设置schema为项目中需要的模式。

配置文件即改为:

< hibernate-reverse-engineering>  < table-filter match-schema = "MILITARYMS_V2" match-name= "asroc" /></ hibernate-reverse-engineering>

至此,该问题解决。

0 0