yegor256
yegor256

Reputation: 105133

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?

Upvotes: 3

Views: 5488

Answers (3)

user1593165
user1593165

Reputation: 615

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.

Upvotes: 0

Andreas Dolk
Andreas Dolk

Reputation: 114797

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

Upvotes: 8

Jigar Joshi
Jigar Joshi

Reputation: 240928

Try Making it..like this

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

Documentations

Upvotes: 1

Related Questions