Solved

Spring Framework's declarative transaction  management

Posted on 2011-09-06
3
330 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

726 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