Solved

Spring Framework's declarative transaction  management

Posted on 2011-09-06
3
305 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

770 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