HibernateTemplate可以和EntityManager共存吗? [英] Can HibernateTemplate coexist with EntityManager?
问题描述
我们有一个spring 3应用程序,它仍然使用不推荐使用的 HibernateTemplate
作为持久性,并且希望迁移到更现代的JPA EntityManager
。
在迁移过程中是否可以同时使用两个API(甚至可能在单个事务中都使用这两个API),以便我们可以以小步骤进行迁移?
或者我们必须做大爆炸吗?
当然,为什么不呢。
最简单的方法是放弃您的 LocalSessionFactoryBean
和 HibernateTransactionManager
配置,并分别用 LocalContainerEntityManagerFactoryBean
和 JpaTransactionManager
替换它。
然后获得 通过这种方式,两种技术应该和平共存。 有些报告称,这样做会导致一个异常,指出 或 We have a spring 3 application that still uses the deprecated Is it possible to use both APIs in parallel during the migration (possibly even both in a single transaction), so that we can do the migration in small steps? Or will we have to do it big bang? Sure, why not. The easiest would be to drop your Then to obtain a This way both technologies should peacefully coexist. There are some reports that doing this leads to a an exception stating or
这篇关于HibernateTemplate可以和EntityManager共存吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! SessionFactory
,添加 HibernateJpaSessionFactoryBean
,公开 SessionFactory
。
没有配置CurrentSessionContext!
。如果你得到它,将以下内容添加到 persistence.xml中
< property name =hibernate.current_session_context_classvalue =org.springframework.orm.hibernate4.SpringSessionContext/>
jpaProperties
c> LocalContainerEntityManagerFactoryBean 。
< property name =jpaProperties>
<道具>
< prop name =hibernate.current_session_context_class> org.springframework.orm.hibernate4.SpringSessionContext< / prop>
<道具>
<属性>
HibernateTemplate
for persistence and want to migrate to the more modern JPA EntityManager
. LocalSessionFactoryBean
and HibernateTransactionManager
configuration and replace it with LocalContainerEntityManagerFactoryBean
and JpaTransactionManager
, respectively. SessionFactory
add the HibernateJpaSessionFactoryBean
, which exposes the underlying SessionFactory
for the EntityManagerFactory
. No CurrentSessionContext configured!
. If you get it add the following to either your persistence.xml
<property name="hibernate.current_session_context_class" value="org.springframework.orm.hibernate4.SpringSessionContext"/>
jpaProperties
of the LocalContainerEntityManagerFactoryBean
.<property name="jpaProperties">
<props>
<prop name="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop>
<props>
<property>