Must every Entity Bean be registered in persistenc

2020-07-05 05:44发布

问题:

I'm using Eclipse Facets for JPA 2.0 and Hibernate 4.2 implementation. I think I recall that in previous project I would not have to register an Entity Bean in the persistence.xml. Am I mistaken?

Annotating a POJO (in this case Pub.java) with @Entity will throw the following error in the Eclipse marker/problem view:

Class "com.jacky.webapp.model.Pub" is managed, but is not listed in the persistence.xml file    Pub.java    /webapp/src/main/java/com/jacky/webapp/model    

Any clue? thanks.

回答1:

As already written here is the solution:

Check you JPA project properties and be sure to select "Discover annotated classes automatically" in the "Persistent class management" section. Doing this should provide the correct validation for your use case.



回答2:

in jpa you have to compile a file called persistence.xml where you tell Hibernate which classes will be managed by your ORM.
Check this question and its accepted answer



回答3:

It's possible when you created the project, you picked "JPA project" instead of "java Project". In case you don't see "Java Project", follow the "other" and under the wizard type "java" to see the "Java Project".