我的 persistence.xml
看起来像:
<persistence>
<persistence-unit name="test">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.XXX.Abc</class>
<properties>
<property name="hibernate.archive.autodetection" value="true" />
..
</properties>
</persistence-unit>
<persistence>
一切正常。当我删除 <class>
指令我从 EntityManager.find(Abc.class, 1)
得到一个异常:
java.lang.IllegalArgumentException: Unknown entity: com.XXX.Abc
虽然我正在使用 @Entity
,但看起来 hibernate 无法发现我的注释类.. 为什么?
最佳答案
hibernate.archive.autodetection
的值是 hibernate 自动发现的元素的 csv 列表。
试试这个:
<property name="hibernate.archive.autodetection" value="class, hbm"/>
延伸阅读
- Hibernate Community Documentation, 2.2.2 - Bootstrapping (有一个包含属性文档的表格)
关于java - 为什么我的 JPA 注释类没有被隐式发现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3819691/