简体   繁体   中英

Hibernate/JPA Annotations — Unknown Entity

An application that has been working well for months has stopped picking up the JPA @Entity annotations that have been a part of it for months. As my integration tests run I see dozens of " org.hibernate.MappingException: Unknown entity: com.whatever.OrderSystem " type errors.

It isn't clear to me what's gone wrong here.

I have no hibernate.cfg.xml file because I'm using the Hibernate Entity Manager. Since I'm exclusively using annotations, there are no .hbm.xml files for my entities. My persistence.xml file is minimal, and lives in META-INF as it is supposed to.

I'm obviously missing something but can't put my finger on it.

I'm using hibernate-annotations 3.2.1, hibernate-entitymanager 3.2.1, persistence-api 1.0 and hibernate 3.2.1. hibernate-commons-annotations is also a part of the project's POM but I don't know if that's relevant.

Is there a web.xml entry that has vanished, or a Spring configuration entry that has accidentally been deleted?

在您的实体类中验证您输入的是javax.persistent.Entity而不是org.hibernate.annotations.Entity

I seem to recall I had a similar issue at one time.

Its a long shot, but if you're not already doing this, have you explicitly specified the provider you are using?

<persistence ...>
   <persistence-unit ...>
      <provider>org.hibernate.ejb.HibernatePersistence</provider> <---- explicit setting
      ....
   </persistence-unit>
</persistence>

Otherwise, I'm not sure?

Is this happening for one specific class (few classes) or all the entity classes. The persistence.xml file has a list of class and or jar files that need to be scanned for @Entity mappings. If it was working earlier you can do a quick diff with the version of persistence.xml that was working correctly. Another issue could be that it is picking up a different persistence.xml file - you can verify this by introducing an error (for eg, make the xml invalid) in the persistence.xml.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM