3

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?

yegor256
  • 97,508
  • 114
  • 426
  • 573

3 Answers3

8

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

Andreas Dolk
  • 111,016
  • 17
  • 174
  • 259
1

Try Making it..like this

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

Documentations

jmj
  • 232,312
  • 42
  • 391
  • 431
0

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.

user1593165
  • 458
  • 3
  • 6