簡體   English   中英

Hibernate / JPA注釋-未知實體

[英]Hibernate/JPA Annotations — Unknown Entity

一個運行了幾個月的應用程序已經停止使用已經有幾個月歷史的JPA @Entity批注。 在運行集成測試時,我看到許多“ org.hibernate.MappingException: Unknown entity: com.whatever.OrderSystem ”類型錯誤。

我不清楚這里出了什么問題。

我沒有hibernate.cfg.xml文件,因為我正在使用Hibernate實體管理器。 由於我僅使用注釋,因此我的實體沒有.hbm.xml文件。 我的persistence.xml文件很小,並且按預期存在於META-INF中。

我顯然丟失了一些東西,但不能動彈。

我正在使用hibernate批注3.2.1,hibernate-entitymanager 3.2.1,persistence-api 1.0和hibernate 3.2.1。 hibernate-commons-annotations也是項目POM的一部分,但我不知道這是否有意義。

是否存在消失的web.xml條目或意外刪除的Spring配置條目?

在您的實體類中驗證您輸入的是javax.persistent.Entity而不是org.hibernate.annotations.Entity

我似乎記得我曾經有過類似的問題。

它的作用很遠,但是,如果您還沒有這樣做,是否已明確指定您正在使用的提供程序?

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

否則,我不確定嗎?

這是針對一個特定類(很少的類)還是所有實體類發生的。 persistence.xml文件包含需要掃描@Entity映射的類和/或jar文件的列表。 如果較早運行,則可以對正常運行的persistence.xml版本進行快速比較。 另一個問題可能是它正在拾取不同的persistence.xml文件-您可以通過在persistence.xml中引入錯誤(例如,使xml無效)來驗證這一點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM