Spring + Hibernate +JTA - HibernateTransactionManager or JTATransactionManager

徘徊边缘 提交于 2019-12-19 09:52:45

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/5936921/spring-hibernate-jta-hibernatetransactionmanager-or-jtatransactionmanager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!