Reputation: 933
What is the difference between Spring JtaTransactionManager
and HibernateTransactionManager
and when to use one in my application? I know about HibernateTransactionManager
and I can use it if I use Hibernate as my ORM tool but I didn't understand when to use JtaTransactionManager
.
Upvotes: 6
Views: 6135
Reputation: 20135
HibernateTransactionManager
is used to manage transactions on top of a single Hibernate SessionFactory
. If your application uses only a JDBC-compliant database to store data (that is, no ERP, JMS queue, file system, etc. is involved) that you access using Hibernate, you can use a HibernateTransactionManager
in your application.
If however you have business operations that can modify multiple data stores at the same time and you need to ensure data consistency across all the stores, you will need to use JTA transactions. JTA support is provided either by JavaEE containers like JBoss, WebLogic or WebSphere or third-party JTA providers like Atomikos or Bitronix. JtaTransactionManager
enables you to integrate a JTA provider with your Spring application. JtaTransactionManager
only facilitates integration of a JTA transaction provider and is not a provider in itself. The underlying data sources that you want to participate in transactions should also support JTA transactions, which is usually implemented in the driver layer. For example, most JDBC drivers have a JTA and a non-JTA implementation.
Upvotes: 15