Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Spring JtaTransactionManager and HibernateTransactionManager

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.

like image 353
Nalla Srinivas Avatar asked Mar 16 '16 07:03

Nalla Srinivas


People also ask

What is Spring JtaTransactionManager?

Spring provides support for JTA-based global transaction implementations through a PlatformTransactionManager implementation called JtaTransactionManager . If you use it on a JavaEE application server, it will automatically find the correct javax. transaction.

What is Hibernatetransactionmanager in Spring?

This transaction manager is appropriate for applications that use a single Hibernate SessionFactory for transactional data access, but it also supports direct DataSource access within a transaction (i.e. plain JDBC code working with the same DataSource).

What is JtaTransactionManager?

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.

What is the use of Jpatransactionmanager?

This transaction manager is appropriate for applications that use a single JPA EntityManagerFactory for transactional data access. JTA (usually through JtaTransactionManager ) is necessary for accessing multiple transactional resources within the same transaction.


1 Answers

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.

like image 50
manish Avatar answered Sep 30 '22 15:09

manish