Springs - SPLessons

Chapter 20

Spring Transaction Management

Spring Transaction Management

Spring Transaction Management, Before Spring exchange, EJB was an effective API accessible offering bean managed  and holder managed exchanges. A database exchange speaks to a solitary unit of work. The idea of exchanges can be depicted as ACID properties as follows.

Programmatic transaction management

The Spring transaction advantage is it gives programmatic and declarative exchange management. 
Programmatic transaction management gives exact control on the limits of the exchange.Example as follows.


Declarative transaction management

Declarative transactions are less intrusive and are characterized in a configuration document.Spring underpins it via  AOP .It created in view of the AOP ideas. This gives an utilization of keeping the cross cutting concerns like exchanges of DAO layer code.

TransactionDefinition Interface

TransactionDefinition  defined as below:

public interface TransactionDefinition {
   int getPropagationBehavior();
   int getIsolationLevel();
   String getName();
   int getTimeout();
   boolean isReadOnly();
Methods Description
int getPropagationBehavior() It returns the propagation behavior.Spring offers the majority of the exchange propagation choices different from EJB CMT.
int getIsolationLevel() It gives back the extent to which this exchange is segregated from the work of different exchanges.
string getName() It returns  the title of exchange.
int getTimeout()  The transaction should complete while returns the time in seconds .
boolean isReadOnly() If exchange is readable then it returns.

Conceivable values for Isolation levels are as per the following

Isolation Description
TransactionDefinition.ISOLATION_DEFAULT It is specific to the data source.
TransactionDefinition.ISOLATION_READ_COMMITTED Shows that filthy peruses are anticipated; non-repeatable peruses and ghost peruses can happen.
TransactionDefinition.ISOLATION_READ_UNCOMMITTED Demonstrates that filthy peruses, non-repeatable peruses and apparition peruses can happen.
TransactionDefinition.ISOLATION_REPEATABLE_READ Demonstrates that filthy peruses and non-repeatable peruses are avoided; ghost peruses can happen.
TransactionDefinition.ISOLATION_SERIALIZE Demonstrates that messy peruses, non-repeatable peruses and ghost peruses are averted.

 Possible values for propagation types are as follows:

Propagation Description
TransactionDefinition.PROPAGATION_MANDATORY Method ought to keep running in an exchange and nothing exists-exception will be thrown.
TransactionDefinition.PROPAGATION_NESTED METHOD ought to keep running in a nested exchange
TransactionDefinition.PROPAGATION_NEVER Current method ought not keep running in a transaction.If exists an exception will be thrown.
TransactionDefinition.PROPAGATION_NOT_SUPPORTED Method ought not keep running in a transaction.existing exchange will be suspended till method finishes the execution.
TransactionDefinition.PROPAGATION_REQUIRED Method ought to keep running in a transaction.If already exists,method will keep running in that and if not,a new transaction will be made.
TransactionDefinition.PROPAGATION_REQUIRES_NEW Create a new transaction, suspending the present transaction if one exists.
TransactionDefinition.PROPAGATION_SUPPORTS Method ought to keep running in another transaction.If already exists,it will be suspended till the method wraps up.


  • Spring Transaction Management – Spring transaction no need of using JTA.
  • Spring Transaction Management – Spring transactions are good at applications by preferring single database.
  • Spring Transaction Management – Spring underpins declarative exchange management through the  AOP .