我可以肯定的是,过去我在JPA 2.0中使用了某种自动检测带有@Entity注释的bean的方法,但是我无法找到方法。您如何做到这一点,而不是class在persistence.xml 的XML元素中列出每个bean ?
class
从Spring 3.1开始,您还可以选择完全忘记persistence.xml,并EntityManagerFactory使用packagesToScan属性进行配置,如下所示:
EntityManagerFactory
packagesToScan
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" p:dataSource-ref="dataSource" p:packagesToScan="${jpa.entity.packages}"> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" p:showSql="${hibernate.show_sql}"/> </property> <property name="jpaProperties"> <props> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> </props> </property> </bean>