读书人

Hibernate报如上异常: org.hibernate.

发布时间: 2012-11-10 10:48:50 作者: rapoo

Hibernate报如下错误: org.hibernate.MappingException: Unknown entity: 解决
控制台报错:

Caused by: org.hibernate.MappingException: Unknown entity: com.SpringMvcTest.model.Questions
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:550)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1338)


分析:

这个异常的意思就是某个类没有被映射。

这里是 com.SpringMvcTest.model.Questions类

解决方法:

需要把类的映射文件加载到hibernate.cfg.xml (如果是spring mvc 看看加的.cfg.xml 方式有么有)
我的原先是:
<property name="mappingDirectoryLocations">
<list>
<!-- <value>classpath:/config/hibernate</value> Mysql -->
<value>classpath:/config/hibernate/a</value> <!--Ms sql -->
</list>
</property>



读书人网 >软件架构设计

热点推荐