Compared with the plain JDBC example (in Java - Data - Transaction Management - Java Transaction API (JTA)):

  • You do not have to mess with opening or closing database connections yourself (try-finally). Instead you use Transaction Callbacks.
  • You also do not have to catch SQLExceptions, as Spring converts these exceptions to runtime exceptions for you

Transaction Configuration

Transaction Creation

Programmatically

TransactionTemplate

  • for imperative code
  • TransactionTemplate will use a PlatformTransactionManager internally, which will use a DataSource

TransactionalOperator

  • for reactive code
  • TransactionalOperator will use a ReactiveTransactionManager internally, which will use a DataSource

Declaratively

@Transactional & @EnableTransactionManagement

  • can be used for both: imperative and reactive?

Transaction - Other

Resources