在使用hibernate 實(shí)體關(guān)聯(lián)映照時(shí)出現(xiàn)了以下異常:
org.hibernate.DuplicateMappingException: Duplicate class/entity mapping com.etoak.entity.Student
at org.hibernate.cfg.Mappings.addClass(Mappings.java:141)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:789)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:546)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:291)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1333)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
at com.etoak.factory.SessionFactory.rebuildSessionFactory(SessionFactory.java:71)
at com.etoak.factory.SessionFactory.getSession(SessionFactory.java:54)
at com.etoak.dao.OneToManyDao.add(OneToManyDao.java:12)
at com.etoak.test.Test.main(Test.java:17)
Exception in thread “main” java.lang.NullPointerException
at com.etoak.dao.OneToManyDao.add(OneToManyDao.java:13)
at com.etoak.test.Test.main(Test.java:17)
網(wǎng)上說(shuō)法基本上都是 配置文件hibernate.cfg.xml中有重復(fù)的映照類。
而我的問(wèn)題卻不在這。
我出現(xiàn)這個(gè)異常的緣由是hibernate映照注解配置錯(cuò)了。將@joinColumn注解放在set屬性上面了。致使映照關(guān)系出錯(cuò)。
所以出這個(gè)問(wèn)題的童鞋可以看下你的實(shí)體關(guān)系映照的書(shū)寫(xiě)是不是正確。
上一篇 STL中set底層實(shí)現(xiàn)方式? 為什么不用hash?
下一篇 在Windows下搭建React Native Android開(kāi)發(fā)環(huán)境(加入下載鏈接)