これまで、JPA 2.0で@EntityでアノテーションされたBeanの自動検出機能を使用していたのは確かですが、 persistence.xmlのclass
XML要素に各Beanをリストする代わりに、どうやってそれを行うのですか?JPA 2.0でエンティティを自動検出する方法
<exclude-unlisted-classes>false</exclude-unlisted-classes>
例えば:あなたはpersistence.xml
に次の行を追加する必要がある
これまで、JPA 2.0で@EntityでアノテーションされたBeanの自動検出機能を使用していたのは確かですが、 persistence.xmlのclass
XML要素に各Beanをリストする代わりに、どうやってそれを行うのですか?JPA 2.0でエンティティを自動検出する方法
<exclude-unlisted-classes>false</exclude-unlisted-classes>
例えば:あなたはpersistence.xml
に次の行を追加する必要がある
春3.1以来、あなたはまた、完全forget persistence.xmlへのオプションを持って、そしてあなたの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>
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" ...>
<persistence-unit name="YourPU" ...>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.logging.level" value="ALL"/>
<property name="eclipselink.ddl-generation"
value="drop-and-create-tables"/>
</properties>
</persistence-unit>
</persistence>
これは受け入れられるはずです。 –
参照Thiventパスカルここに答える:Do I need <class> elements in persistence.xml?
する方法は異なりますが、JPA自体は自動スキャンをサポートしていません。あなたのエンティティを参照する最もシンプルでクリーンな方法は、あなたのモデルをjarファイルにパッケージ化し、それを参照することです。<jar-file>MyModel.jar</jar-file>
私はそれを知っていますが、私はJPA persistence.xmlについて尋ねました。 – LuckyLuke
私は知っています。このオプションについても言及したかったのです。問題を解決する良い方法です(エンティティクラスの自動検出)。 – zagyi