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

yeg*_*256 3 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>
Run Code Online (Sandbox Code Playgroud)

一切正常.当我删除<class>指令时,我得到一个例外EntityManager.find(Abc.class, 1):

java.lang.IllegalArgumentException: Unknown entity: com.XXX.Abc
Run Code Online (Sandbox Code Playgroud)

看起来hibernate无法发现我的注释类,虽然我正在使用@Entity..为什么?

And*_*s_D 8

它的值hibernate.archive.autodetection是由hibernate自动发现的csv元素列表.

试试这个:

<property name="hibernate.archive.autodetection" value="class, hbm"/>
Run Code Online (Sandbox Code Playgroud)

进一步阅读