Java Hibernate/JPA 注释——未知实体
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/270074/
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
Hibernate/JPA Annotations -- Unknown Entity
提问by Jim Kiley
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.
几个月来一直运行良好的应用程序已停止获取已成为其@Entity
一部分的 JPA注释几个月。当我的集成测试运行时,我看到了几十个“ org.hibernate.MappingException: Unknown entity: com.whatever.OrderSystem
”类型的错误。
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.
我没有hibernate.cfg.xml
文件,因为我使用的是 Hibernate Entity Manager。由于我只使用注释,因此我的实体没有 .hbm.xml 文件。我的persistence.xml
文件很小,并且META-INF
按预期保存。
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.
我正在使用 hibernate-annotations 3.2.1、hibernate-entitymanager 3.2.1、persistence-api 1.0 和 hibernate 3.2.1。hibernate-commons-annotations 也是项目 POM 的一部分,但我不知道这是否相关。
Is there a web.xml entry that has vanished, or a Spring configuration entry that has accidentally been deleted?
是否存在已消失的 web.xml 条目,或意外删除的 Spring 配置条目?
采纳答案by toolkit
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?
否则,我不确定?
回答by toolkit
verify in your entity classe that you import javax.persistent.Entity and not org.hibernate.annotations.Entity
在您的实体类中验证您导入 javax.persistent.Entity 而不是 org.hibernate.annotations.Entity
回答by kamal.gs
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.
这是针对一个特定类(少数类)还是所有实体类发生的。persistence.xml 文件包含需要扫描以获取@Entity 映射的类和/或 jar 文件的列表。如果它更早运行,您可以对运行正常的persistence.xml 版本进行快速比较。另一个问题可能是它选择了一个不同的persistence.xml 文件——您可以通过在persistence.xml 中引入一个错误(例如,使xml 无效)来验证这一点。