JPA 2.0 : Adding entity classes to PersistenceUnit *from different jar* automatically
December 24, 2013 Leave a comment
There are several way to solve it:
- As described in Do I need <class> elements in persistence.xml?, you can set
hibernate.archive.autodetection
property and Hibernate should be able to look up all annotated classes from classpath. However, that’s not JPA spec compliant. - If you are using Spring, from Spring 3.1.2 (or probably even a bit earlier), in
LocalContainerEntityManagerFactoryBean
, you can definepackageToScan
which will askLocalContainerEntityManagerFactoryBean
to scan in classpath to find all annotated classes. Again, not JPA spec compliant.