如何在 JPA 2.0 中自动检测实体 [英] How to auto detect entities in JPA 2.0
本文介绍了如何在 JPA 2.0 中自动检测实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很确定我过去在 JPA 2.0 中使用了某种用 @Entity 注释的 bean 的某种自动检测,但我无法找到方法.您如何做到这一点而不是在persistence.xml 的class
XML 元素中列出每个bean?
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屋!
查看全文