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
  • 102,010
  • 123
  • 446
  • 597

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
  • 113,398
  • 19
  • 180
  • 268
1

Try Making it..like this

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

Documentations

jmj
  • 237,923
  • 42
  • 401
  • 438
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
  • 503
  • 3
  • 6