开发者

why my JPA annotated classes are not discovered implicitly?

My persistence.xml looks like:

<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>

Everything works fine. When I'm removing <class> directive I'm getting an exception from EntityManager.find(Abc.class, 1):

java.lang.IllegalArgumentException: Unknown entity: com.XXX.Abc

Looks like hibernate can't discover my annotated classes although I'm using @Entity.. Why?


The value of the hibernate.archive.autodetection is a csv list of elements that are autodiscovered by hibernate.

Try this instead:

<property name="hibernate.archive.autodetection" value="class, hbm"/>

Further Reading

  • Hibernate Community Documentation, 2.2.2 - Bootstrapping (has a table with properties documentation)


Try Making it..like this

<property name="hibernate.archive.autodetection" value="class" />   

Documentations


I think that Hibernate looks for classes in the same codesource as the persistence.xml. So, for example, if you have persistence.xml in a folder and classes in a separate jar, Hibernate won't find them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜