When using annotation to configure SSH2 project, I encountered this error:
org.hibernate.MappingException: Unknown entity: com.jp.bean.TUser at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:628) at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:91) at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:906) at org.hibernate.impl.SessionImpl.get(SessionImpl.java:843) at org.hibernate.impl.SessionImpl.get(SessionImpl.java:836) at com.jp.dao.UserDao.getTUser(UserDao.java:31) ......
Prompt for an unknown entity. possible reason:
1. When configuring the entity class, import org.hibernate.annotations.Entity by mistake when importing the package for @Entity, it should be changed to import javax.persistence.Entity;
2. The path is wrong when configuring entity scanning in applicationContext.xml. For example, if the entity class is stored in the com.demo.entity package, the path should be set to <property name="packagesToScan" value="com.demo.*"/ > instead of <property name="packagesToScan"value="com.demo.entity.*"/> which means that the configuration mapping directory is one layer less than the actual one .
or use directly
<property name="annotatedClasses"> <list> <value>com.demo.entity.TUser</value> ...... </list> </property>
Specify the corresponding entity class (when there are fewer entity classes).
Source: http://www.thinksaas.cn/topics/0/105/105980.html