eclipse 每个实体 Bean 都必须在persistence.xml 中注册吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18051055/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Must every Entity Bean be registered in persistence.xml?
提问by feder
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?
我将 Eclipse Facets 用于 JPA 2.0 和 Hibernate 4.2 实现。我想我记得在以前的项目中我不必在persistence.xml 中注册实体Bean。我错了吗?
Annotating a POJO (in this case Pub.java) with @Entity will throw the following error in the Eclipse marker/problem view:
使用@Entity 注释 POJO(在本例中为 Pub.java)将在 Eclipse 标记/问题视图中抛出以下错误:
Class "com.Hymany.webapp.model.Pub" is managed, but is not listed in the persistence.xml file Pub.java /webapp/src/main/java/com/Hymany/webapp/model
Any clue? thanks.
有什么线索吗?谢谢。
回答by kotev
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.
检查您的 JPA 项目属性,并确保在“持久类管理”部分中选择“自动发现带注释的类”。这样做应该为您的用例提供正确的验证。
回答by Luca Basso Ricci
in jpa you have to compile a file called persistence.xmlwhere you tell Hibernate which classes will be managed by your ORM.
Check this questionand its accepted answer
在 jpa 中,您必须编译一个名为persistence.xml的文件,您可以在其中告诉 Hibernate 哪些类将由您的 ORM 管理。
检查这个问题及其接受的答案
回答by Arash
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".
创建项目时,您可能选择了“JPA 项目”而不是“java 项目”。如果您没有看到“Java 项目”,请按照“其他”并在向导下键入“java”来查看“Java 项目”。