在使用Hibernate连接SqlServer时,会出现如下错误:
org.hibernate.cfg.JDBCBinderException: Duplicate class name 'CheckConstraints' generated for 'org.hibernate.mapping.Table
(test.sys.check_constraints)'. Same name where generated for 'org.hibernate.mapping.Table(test.sys.check_constraints)'
Duplicate
class name 'CheckConstraints' generated for 'org.hibernate.mapping.Table(test.sys.check_constraints)'. Same name where generated
for 'org.hibernate.mapping.Table(test.sys.check_constraints)'
<No message>
这是因为在数据库中有其它的系统表参与了逆向生成,出现的错误。解决方法:配置逆向文件hibernate.reveng.xml,设定只有需要的表才参与逆向生成。
生成的文件内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>
<table-filter match-catalog="test" match-schema="dbo" match-name="CLASSES"/>
<table-filter match-catalog="test" match-schema="dbo" match-name="STUDENTS"/>
</hibernate-reverse-engineering>