Duplicate class/entity mapping 问题解决方法

 开发环境:myeclipse8+spring2.5+hibernate3+mysql5

首先在mysql中建立表t,然后使用myeclipse中 Db视图,选择该表t,使用反转功能生成 hibernate.cfg.xml +pojo+tDAO+HibernateSessionFactory+t.hbm.xml

建立main类,访问数据库,报错:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'TDAO' defined in file [D:\Workspaces\MyEclipse 8.6\Demo\src\applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory';

...

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [D:\Workspaces\MyEclipse 8.6\Demo\src\applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: Duplicate class/entity mapping T

...

Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping T

...

解决方法:

hibernate.cfg.xml 中session-factory ,配置了

<mapping resource="T.hbm.xml" />

此项和applicationContext.xml 中 sessionFactory 的

<property name="mappingResources"> 

<list>

<value>T.hbm.xml</value>

</list>

</property>

冲突, 把hibernate.cfg.xml 中 的<mapping resource=""/> 注销即可

你可能感兴趣的:(Duplicate class/entity mapping 问题解决方法)