这个周在复习Hibernate,遇到的错误记录下来。
- org.hibernate.MappingException: Unknown entity: com.sandy.pojo.User
- at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:597)
- at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1339)
- at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:98)
- at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
- at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
- at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
- at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
- at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
- at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:536)
- at org.hibernate.impl.SessionImpl.save(SessionImpl.java:524)
- at org.hibernate.impl.SessionImpl.save(SessionImpl.java:520)
- at com.sandy.dao.BaseHibernateDao.add(BaseHibernateDao.java:26)
- at com.sandy.dao.UserDaoImpl.add(UserDaoImpl.java:15)
- at com.test.TestCRUD.testAdd(TestCRUD.java:19)
- at com.test.TestCRUD.main(TestCRUD.java:37)
错误原因:hibernate.cfg.xml配置文件里,没有配置user.hbm.xml映射文件。