org.hibernate.MappingException: Unknown entity异常是新手学习hibernate的时候经常遇到的问题,这值得注意一下。下边是异常截图
MappingException: Unknown entity解决方案――org.hibernate.MappingException: UnknownMappingException: Unknown entity解决方案 1、
org.hibernate.MappingException: Unknown entity异常详细信息如下:
org.hibernate.MappingException: Unknown entity: com.gis520.model.Emp_emp
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:628)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1366)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
…………
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
MappingException: Unknown entity解决方案――解决方案:MappingException: Unknown entity解决方案 1、
原因分析1:
可能是因为使用注解的时候没有导入正确的包。要清楚,Entity包是javax.persistence.Entity;而不是hibernate包下的annotation
MappingException: Unknown entity解决方案 2、
原因分析2:
使用注解时没有在*.cfg.xml下配置<mapping class=""/>,从而造成org.hibernate.MappingException: Unknown entity异常的原因
MappingException: Unknown entity解决方案_exception
MappingException: Unknown entity解决方案 3、
org.hibernate.MappingException: Unknown entity解决方法就是以上两个原因。如果你使用注解,上边的两个一定要正确。如果是使用的是*.hbm.xml文件,则查看*.hbm.xml是否加入了引用即可。排除后即可解决异常。
MappingException: Unknown entity解决方案――注意事项有用请点“赞”或分享给朋友哦!更多hibernate异常请查看劳黑炭更多经验