My question:
Is there a way to tell Spring/JPA to automatically detect classes annotated with @Entity?
Background:
This is my configuration of the entityManagerFactory
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
</bean>
... and this is my persistence.xml ...
<persistence-unit name="foo">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate..." value="..."/>
<property ...
</properties>
</persistence-unit>
This configuration is working. But: When I add the following line to my entityManagerFactory configuration
<property name="persistenceXmlLocation" value="META-INF/persistence.xml" />
JPA doesn't find my classes annotated with @Entity. So, I get Exceptions like this one:
java.lang.IllegalArgumentException: Unknown entity: foo.Bar
where foo.Bar is a class annotated with @javax.persistence.Entity
When I now add
<class>foo.Bar</class>
to my persistence.xml, everything's fine again. But why do I have to specify my classes in persistence.xml when using persistenceXmlLocation and otherwise not?
Note: You might ask why I want to use persistenceXmlLocation: It would solve this problem.