Solved

Spring Framework's declarative transaction  management

Posted on 2011-09-06
3
309 Views
Last Modified: 2012-05-12
I would like to know about
 Spring Framework's declarative transaction  management and its similarities, differences compared to  EJB CMT(container managed transaction). What are advantages, disadvantages, when, how, where we use each one of them. I am not clear on this concept. thanks in advance
0
Comment
Question by:gudii9
  • 2
3 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36493494
0
 
LVL 7

Author Comment

by:gudii9
ID: 36589953
>>>>Feature of Spring Transaction :

    Spring Framework’s declarative transaction management is not tied to JTA therefore works in any environment. It can work with JDBC, JDO, Hibernate or other transactions under the covers, with configuration changes only.




    For eg in this class below

    }

    public class RecordHibernateDAO implements RecordsDAO {

    public void addRecords(Records record ){

    //do something

    }

We can mange the transaction by adding this annotation for the method addrecords

    @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)

    }

    public void addRecords(Records record ){

    //do something

The Spring Framework enables declarative transaction management to be applied to any class, not merely special classes such as EJBs. For eg in the above example instead of HibernateDAO class we could have a plain java class on which transaction capabilities can be applied. This makes life so much easy for an application developer. Now he is not constrained by “business logic” residing inside EJB only.







why "}" is kind of hanging in the air. Why @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW) declared on top of "{"


>>>>    The Spring Framework offers declarative rollback rules: this is a feature with no EJB equivalent. Both programmatic and declarative support for rollback rules is provided. This especially comes handy when you want transaction to be rolled back for certain exceptions only.


i thought we can do it in EJB.

>>>The Spring Framework gives you an opportunity to customize transactional behavior, using AOP. For example, if you want to insert custom behavior in the case of transaction rollback, you can. You can also add arbitrary advice, along with the transactional advice. With EJB CMT, you have no way to influence the container’s transaction management other than setRollbackOnly().

whar it means by custom behaviour in case of transaction rollback how it is different from setRollbackOnly().
  i was not clear on this concept.

i was not clear on how JTA is related to ORM frameworks like hibernate or JDBC or JDO etc.can you please advise        
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 36590040



    @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)

    }  // I think this is a misprint  - just extraneous charcter

raed this about roolback behavior

http://biese.wordpress.com/2006/10/30/54/

c. You can define rollback rules declaratively. Whereas EJB will not automatically roll back a transaction on an uncaught application exception (only on unchecked exceptions, other types of Throwable and “system” exceptions), application developers often want a transaction to roll back on any exception. Spring transaction management allows you to specify declaratively which exceptions and subclasses should cause automatic rollback. Default behaviour is as with EJB, but you can specify automatic rollback on checked, as well as unchecked exceptions. This has the important benefit of minimizing the need for programmatic rollback, which creates a dependence on the Spring transaction API (as EJB programmatic rollback does on the EJBContext).

You can read about JTA and Hibernate here:
http://community.jboss.org/wiki/SessionsAndTransactions



0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question