如何在JPA 2.0中自动检测实体 [英] How to auto detect entities in JPA 2.0
本文介绍了如何在JPA 2.0中自动检测实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很确定我过去在JPA 2.0中使用了@Entity注释的bean的某种自动检测,但我无法弄清楚如何。你如何做而不是将每个bean列在persistence.xml中的 class
XML元素中?
I am pretty sure that I used some sort of auto detection of beans annotated with @Entity in JPA 2.0 in the past but I am not able to find out how. How do you do that instead of listing each bean in a class
XML element in the persistence.xml?
推荐答案
从Spring 3.1开始,您还可以选择完全忘记persistence.xml ,并配置 EntityManagerFactory
使用 packagesToScan
属性,类似于:
Since Spring 3.1, you also have the option to forget persistence.xml altogether, and configure your EntityManagerFactory
using the packagesToScan
property, similar to this:
<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>
这篇关于如何在JPA 2.0中自动检测实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文