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
.
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.
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).
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With