[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Spring Framework's declarative transaction  management

Posted on 2011-09-06
3
Medium Priority
?
352 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
A solution for Fortify Path Manipulation.
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 basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

649 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