Spring Transaction Management Tutorial

What is Transaction Management

Sequence of action that will be performed to complete database operation and its management is known as Transaction Management. All these action in combination will be treated as ONE action only. So that DB doesn’t fall in inconsistent mode ever. For more details you can search for ACID property of relation DB.

Type of Transaction Management

In J2EE, Transaction Management can be divided in two types.

  1. Global Transaction
  2. Local Transaction

Global Transaction

  • Use to work with multiple transaction resources like RDBMS or Message Queue (Pros)
  • Managed by Application Server (WebSphere, Weblogic) using JTA (Cons)
  • JNDI is required to use JTA
  • Code can not be reused as JTA is available at server level(Cons)
  • Example of Global Transaction : EJB CMT

Local Transaction

  • Use to work with specific resource(transaction associated with JDBC)
  • Can not work across multiple transaction resource opposite to Global transaction (cons)
  • Most of web application uses only single resources hence it is best option to use in normal app.

Spring Framework Transaction Management

As you can see above there are some pros and cons associated with both approach. Spring transaction management tries to resolve the problem of both transactions. Consistent programming model approach can be used in any environment. Same code will work for different transactions management in different environment.

Different Approach for transaction management

Spring supports two different approach for transaction management.

Programmatic Transaction Management

Here you will write code for transaction management.Spring API dependency. Not good for maintenance. Good for development. Flexibity.

Declarative Transaction Management

Here you will use XML or annotation for transaction management. Less flexible but preferable over programmatic approach. In normal case no code is required for transaction management.

Spring transaction management abstraction

To understand transaction mangement you should understand abstraction(Transaction strategy) in Spring. Which is defined in Spring using PlatformTransactionManager Interface.


As you can see in PlatformTransactionManager Interface all methods throw TransactionException. This Exception itself is UncheckedException means developer is not forced to handle these exceptions. 


TransactionDefinition is an Interface which specifies below 4 points.

  1. Isolation
  2. Propagation
  3. Timeout
  4. Read-Only status


Degree to which particular transaction is isolated from other Transaction.

Below is the list of Isolation level and their details

[accordion] [accordion-group title=”DEFAULT“]


Default isolation level. It uses the isolation of underlying datasource.

[/accordion-group] [accordion-group title=”READ_COMMITTED“]


Dirty reads NOT supported; Non-repeatable reads and Phantom reads can occur.

[/accordion-group] [accordion-group title=”READ_UNCOMMITTED“]


Dirty reads / Non-repeatable reads / Phantom reads all can occur.

[/accordion-group] [accordion-group title=”REPEATABLE_READ“]


Dirty reads and non-repeatable reads are prevented; phantom reads can occur.

[/accordion-group] [accordion-group title=”SERIALIZABLE“]


Dirty reads, non-repeatable reads and phantom reads are prevented.

[/accordion-group] [/accordion]



[accordion-group title=”MANDATORY”]


Support a current transaction

[/accordion-group] [accordion-group title=”NESTED”]


Execute within a nested transaction if a current transaction exists

[/accordion-group] [accordion-group title=”NEVER”]


Execute non-transactionally

[/accordion-group] [accordion-group title=”NOT_SUPPORTED”]


Execute non-transactionally

[/accordion-group] [accordion-group title=”REQUIRED”]


Support a current transaction

[/accordion-group] [accordion-group title=”REQUIRES_NEW”]


Create a new transaction, suspend the current transaction if one exists.

[/accordion-group] [accordion-group title=”SUPPORTS”]


Support a current transaction, execute non-transaction if none exists.



This setting is used to define how long this transaction may run before timing out (candidate for rolled back by the underlying transaction infrastructure).

Read-Only Status

This setting is used to specify the a read-only transaction. As read only transactions does not modify any data. Hence it is optimized in some case.

About the author

V Gautam

Me & Jayshree Singh. Main brain behind this blog/QnA site. We have written all these article as per my personal experience. I have published it mainly to help. These articles might have some problems. So bear with me and let me know if you find any problem in any of the article. You can find me on

1 Comment

  • This is a very good intro. Can you take it one step further and explain what happens inside SpringMVC and Hibernate when a user transaction span several forms and pages.

    Many thanks,

Leave a Comment