In Spring, TransactionManager is the root type of the transaction abstraction. Since Spring 5.2 it is a marker interface with no methods. It has two sub-interfaces: PlatformTransactionManager for imperative code and ReactiveTransactionManager for reactive code. Implementations such as DataSourceTransactionManager and JpaTransactionManager hide the details of JDBC, JPA or JTA behind a single programming model.
That abstraction is what lets you switch from JDBC to JPA, or to a distributed transaction, without changing your @Transactional service code.
Methods like getTransaction() and commit() are often attributed to TransactionManager, but they belong to PlatformTransactionManager, not to TransactionManager itself.
TransactionDefinition carries the propagation, isolation level, timeout and read-only flag.TransactionStatus describes the running transaction: whether it is new, rollback-only or completed, and lets you call setRollbackOnly().ReactiveTransactionManager offers the same operations returning Mono, for use with R2DBC and reactive repositories.Do not confuse this with jakarta.transaction.TransactionManager, which is the JTA interface of an application server and has methods like begin() and suspend().
| Implementation | Use it for |
|---|---|
DataSourceTransactionManager | Plain JDBC, JdbcTemplate, MyBatis, jOOQ |
JpaTransactionManager | JPA, including Hibernate and Spring Data JPA; also exposes the JDBC connection |
JtaTransactionManager | Distributed transactions across several resources |
R2dbcTransactionManager | Reactive relational access with R2DBC |
JdbcTransactionManager | Extension of the data source manager with better exception translation |
The dedicated HibernateTransactionManager was tied to the native Hibernate session API and was removed in Spring Framework 6. With current Hibernate, use JpaTransactionManager.
Spring Boot creates the right manager automatically based on what is on the classpath. With Spring Data JPA you get a JpaTransactionManager, with only JDBC a DataSourceTransactionManager.
The @Transactional annotation is a declaration. A proxy intercepts the call, asks the manager for a transaction according to the annotation settings, runs your method, and then commits or rolls back.
Spring uses the bean named transactionManager by default. With several data sources, name the manager in the annotation:
When you need explicit control, use TransactionTemplate instead of calling the manager yourself. It handles commit and rollback.
executeWithoutResult commits when the callback returns normally and rolls back on a runtime exception or setRollbackOnly(). For reactive code, use TransactionalOperator.
JpaTransactionManager also covers JDBC on the same DataSource, but not a second database.JtaTransactionManager) with an XA-capable provider. Many systems avoid this and use idempotent steps, an outbox or sagas.defaultTimeout and rollbackOnCommitFailure on the manager if you need global defaults.ReactiveTransactionManager.TransactionManager is an empty marker supertype added in Spring 5.2. PlatformTransactionManager is the imperative interface with getTransaction, commit and rollback.
It picks one from the classpath: JpaTransactionManager with JPA, DataSourceTransactionManager with plain JDBC, and R2dbcTransactionManager with R2DBC.
Define one manager per data source and give each a qualifier. Reference it with @Transactional("name").
Rarely. Use @Transactional for most code and TransactionTemplate when you need programmatic control.
The Spring TransactionManager family gives you one consistent transaction API over JDBC, JPA, JTA and R2DBC. TransactionManager is the marker, PlatformTransactionManager carries the operations, and concrete classes bind them to a resource. Use @Transactional day to day, pick the manager that matches your data access technology, and prefer TransactionTemplate for programmatic work.