Solved

Spring Framework's declarative transaction  management

Posted on 2011-09-06
3
299 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
Comment Utility
0
 
LVL 7

Author Comment

by:gudii9
Comment Utility
>>>>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
Comment Utility



    @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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now