问题
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