views:

6597

answers:

3

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?

+2  A: 

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?

toolkit
This resolved it. Thank you. I still don't understand why it spontaneously stopped working but I'm happy to have a solution.
Jim Kiley
I think it might not have been your hibernate dependency that changed, but perhaps the JPA-persistence API dependency itself. From what I recall, when I updated to a later version of the persistence API, things stopped working?
toolkit
It may also be that you might have only had one persistence provider, but a new dependency may have introduced a second persistence provider, which caused JPA to lose its way?
toolkit
+2  A: 

verify in your entity classe that you import javax.persistent.Entity and not org.hibernate.annotations.Entity

A: 

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 e.g., make the xml invalid) in the persistence.xml.

kamal.gs