Spring + Hibernate + JTA - HibernateTransactionManager或JTATransactionManager [英] Spring + Hibernate +JTA - HibernateTransactionManager or JTATransactionManager
问题描述
我想集成 Spring 和 Hibernate ,并使用 JTA 管理事务。我也想把事务处理委托给App服务器,在我的例子中是JBoss。我有一个关于Spring中 transactionManager bean配置的查询:
$ b <1>我们可以使用 HibernateTransactionManager 并在hibernate.properties文件中设置属性 hibernate.transaction.factory_class 和 hibernate.transaction.manager_lookup_class ?
如果没有,为什么?
<2>或者,我们是否应该使用 JTATransactionManager ?
在选项(2)中,是否还需要在中设置属性(hibernate.transaction.factory_class,hibernate.transaction.manager_lookup_class) hibernate.properties ?
谢谢。
如果你想委托给应用服务器,你必须使用JTATransactionManager,据我所知,HibernateTransactionManager不是JTA事务管理器。
单个Hibernate SessionFactory的PlatformTransactionManager实现。将Hibernate Session从指定的工厂绑定到线程,可能允许每个工厂有一个线程绑定的Session。 SessionFactoryUtils和HibernateTemplate知道线程绑定的会话并自动参与这些事务。需要支持这种事务处理机制的Hibernate访问代码需要使用其中的任何一个或者通过SessionFactory.getCurrentSession()。
I want to Integrate Spring and Hibernate and use JTA for managing the transactions. I would also like to delegate transaction handling to the App server, which in my case is JBoss. I have a query regarding the configuration of the "transactionManager" bean in Spring:
1) Can we use HibernateTransactionManager and set the the properties hibernate.transaction.factory_class and hibernate.transaction.manager_lookup_class in hibernate.properties file? If not, why?
2) Or, should we use JTATransactionManager?
In option (2), do we still need to set the properties("hibernate.transaction.factory_class", "hibernate.transaction.manager_lookup_class") in hibernate.properties?
Thanks.
If you want to delegate to the appserver, you have to use JTATransactionManager to my knowledge, HibernateTransactionManager is not a JTA transaction manager.
PlatformTransactionManager implementation for a single Hibernate SessionFactory. Binds a Hibernate Session from the specified factory to the thread, potentially allowing for one thread-bound Session per factory. SessionFactoryUtils and HibernateTemplate are aware of thread-bound Sessions and participate in such transactions automatically. Using either of those or going through SessionFactory.getCurrentSession() is required for Hibernate access code that needs to support this transaction handling mechanism.
这篇关于Spring + Hibernate + JTA - HibernateTransactionManager或JTATransactionManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!