[BUG01]
最近在写一个hbm方式的Hibernate,
在同一个工程的两个包中写了两个相同名字的类,运行时候错误信息如下:
Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource slw03bag/Student.hbm.xml
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3819)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXmlQueue(Configuration.java:3808)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3796)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1412)
at org.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:974)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:188)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:156)
at slw03bag.StudentTest.test01Init(StudentTest.java:12)
at slw03bag.StudentTest.main(StudentTest.java:8)
Caused by: org.hibernate.DuplicateMappingException: duplicate import: Student refers to both slw03bag.Student and slw03.Student (try using auto-import="false")
at org.hibernate.cfg.Configuration$MappingsImpl.addImport(Configuration.java:2892)
at org.hibernate.cfg.HbmBinder.bindPersistentClassCommonValues(HbmBinder.java:681)
at org.hibernate.cfg.HbmBinder.bindClass(HbmBinder.java:595)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:325)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:178)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3816)
... 8 more
提示中已经将处理的方法解释清楚了,就是将其中一个的hbm文件中<hibernate-mapping>
更改为<hibernate-mapping auto-import="false">
BUG解决了,不过需要注意的是添加了auto-import="false"的对应类,
今后在hibernate相关的使用中都需要使用全限定名。