java - 为什么我的 JPA 注释类没有被隐式发现?

标签 java hibernate jpa

我的 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"/>

延伸阅读

关于java - 为什么我的 JPA 注释类没有被隐式发现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3819691/

相关文章:

java - 单元测试的 Hibernate 覆盖策略

hibernate - 使 JPA EntityManager session 无效

Java Paths.get .... readAllBytes(path)) 不适用于相对路径

java - 当输入来自多个文件时如何使用参数化 junit?

hibernate - 如何在 HQL Hibernate 中将列的大小写更改为 Upper

hibernate - JPA实体关系: Cascade on delete

java - 如何在 Spring Data JPA 或 Hibernate 中保持 "in"子句中提供的顺序

java - JPA 和数据库 Flex 字段

java - 为什么这个 TextArea 不返回非粗体格式,或者 Font.PLAIN 就像 "add-on"一样?

java - 捕获所有其他未预料到的异常