永続性ユニットを定義せずに、サービスクラスにentityManagerを挿入できます。persistence-unitを定義せずにentityManagerを挿入できます
これは私の設定です:私のサービスクラスで
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
</bean>
<jpa:repositories base-package="com.example"></jpa:repositories>
:
@PersistenceContext
private EntityManager entityManager;
// THIS WORKS!
final Session session = entityManager.unwrap(Session.class);
、それが原因でJPAは次のとおりですリポジトリ?
entityManagerFactoryは、entityManagerを作成し、指定されたデータソースを使用する必要があります。したがって、注入が機能します。 '' 'jpa:repositoies''は単に' 'Repository''を拡張してクラスを検索して登録するパッケージ(とサブパッケージ)をSpringに伝えます。 – dambros