Scanning

Scanning for Entities with JPA

JPA scanning isn't very "thorough", so if the domain model entities are in a different location/component, JPA does not find them. An easy solution is to use Spring to scan for the @Entity annotation on the classpath and add any found to the persistence unit.

sidaof has a class to do so, EntityPersistenceUnitPostProcessor.

To use, configure it as a Spring bean, adding it as a persistenceUnitPostProcessors definition to the entityManagerFactory bean definition. For exampmle:

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  ...
  <property name="persistenceUnitPostProcessors">
    <bean class="net.sf.sidaof.spring.EntityPersistenceUnitPostProcessor">
      <property name="packages" value="com.mypackage.domain" />
    </bean>
  </property>
  ...
</bean>