Hibernate Unknown Entity Exception solution

Source: Internet
Author: User

  1. Org.hibernate.MappingException:Unknown entity exception details are as follows:

    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)

    END

Solution:
    1. Cause Analysis 1:

      This may be because the correct package was not imported when using annotations. To be clear, the Entity package is javax.persistence.Entity, not the annotation under Hibernate package.

    2. Cause Analysis 2:

      <mapping class= ""/> is not configured under *.cfg.xml when using annotations, which causes Org.hibernate.MappingException:Unknown entity exception

    3. 3

      Org.hibernate.MappingException:Unknown Entity solution is the above two reasons. If you use annotations, the top two must be the correct one. If you are using a *.hbm.xml file, see if *.hbm.xml has added a reference. Exceptions can be resolved after elimination.

Hibernate Unknown Entity Exception solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.