首页 > 学院 > 开发设计 > 正文

Hibernate异常--->关于Hibernate 映射当中的重复映射问题

2019-11-06 06:51:19
字体:
来源:转载
供稿:网友
...Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping Two.Person  //意思是重复的Two.person类...解决方法:hibernate.cfg.xmlsession-factory ,配置了<mapping resource="Two/Person.hbm.xml" />此项和测试项app2中 .addClass(Person.class)冲突, 把hibernate.cfg.xml 中 的<mapping resource=""/> 注销即可

错误来源:

sf工厂小工具Person.class

    sf = new Configuration()            .configure()            .addClass(Person.class)  //(测试) 会自动加载映射文件:Person.hbm.xml

            .buildSessionFactory();

hibernate.cfg.xml也有Person.hbm.xml(里面包含着Person类)

  <session-factory>

                     <mapping resource="Two/Person.hbm.xml"/>  </session-factory>

所以爆出重复加载类的异常


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表