Transaction Management in Spring by R4R Team

Transaction Management in Spring:-

Introduction of Spring Framework 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.


Comprehensive transaction support is among the most compelling reasons to use the Spring Framework. The Spring Framework provides a consistent abstraction for transaction management that delivers the following benefits:


1 Consistent programming model across different transaction APIs such as Java Transaction API (JTA), JDBC, Hibernate, Java Persistence API (JPA), and Java Data Objects (JDO).


2 Support for declarative transaction management.

3 Simpler API for programmatic transaction management than complex transaction APIs such as JTA.

4 Excellent integration with Spring’s data access abstractions.


The following sections describe the Spring Framework’s transaction value-adds and technologies.


1 Advantages of the Spring Framework’s transaction support model describes why you would use the Spring Framework’s transaction abstraction instead of EJB Container-Managed Transactions (CMT) or choosing to drive local transactions through a proprietary API such as Hibernate.


2 Understanding the Spring Framework transaction abstraction outlines the core classes and describes how to configure and obtain DataSource instances from a variety of sources.


3 Synchronizing resources with transactions describes how the application code ensures that resources are created, reused, and cleaned up properly.


4 Declarative transaction management describes support for declarative transaction management.


5 Programmatic transaction management covers support for programmatic (that is, explicitly coded) transaction management.


Type of Transaction Management :-

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

1 Global Transaction

2 Local Transaction


1 Global Transaction

1.1 Use to work with multiple transaction resources like RDBMS or Message Queue (Pros)

1.2 Managed by Application Server (WebSphere, Weblogic) using JTA (Cons)

1.3 JNDI is required to use JTA

1.4 Code can not be reused as JTA is available at server level(Cons)

1.5 Example of Global Transaction : EJB CMT


2 Local Transaction

2.1 Use to work with specific resource(transaction associated with JDBC)

2.2 Can not work across multiple transaction resource opposite to Global transaction (cons)

2.3 Most of web application uses only single resources hence it is best option to use in normal app.


Programmatic and Declarative :-

Spring supports two types of transaction management:

1 Programmatic transaction management: This means that you have manage the transaction with the help of programming. That gives you extreme flexibility, but it is difficult to maintain.


2 Declarative transaction management: This means you separate transaction management from the business code. You only use annotations or XML based configuration to manage the transactions. 

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!