Thursday, 21 April 2016

What are different Transaction attributes in Spring ? How these are counterparts for all EJB transaction attributes ?


Both Spring and EJB give the user the freedom to choose from programmatic and declarative transaction management.

The EJB specification has already defined six basic transaction attributes. Similarly, Spring has counterparts for all six different transaction attributes. In fact, Spring has one more attribute PROPAGATION_NESTED.

1. PROPAGATION_REQUIRED (REQUIRED in EJB)
    Support a current transaction, create a new one if none exists.

2. PROPAGATION_REQUIRES_NEW (REQUIRES_NEW in EJB)
    Create a new transaction, suspend the current transaction if one exists.

3. PROPAGATION_NOT_SUPPORTED (NOT_SUPPORTED in EJB)
    Execute non-transactionally, suspend the current transaction if one exists.

4. PROPAGATION_SUPPORTS (SUPPORTS in EJB)
    Support a current transaction, execute non-transactionally if none exists.

5. PROPAGATION_MANDATORY (MANDATORY in EJB)
    Support a current transaction, throw an exception if none exists.

6. PROPAGATION_NEVER (NEVER in EJB)
    Execute non-transactionally, throw an exception if a transaction exists.

7. PROPAGATION_NESTED (No equivalent in EJB)
    Execute within a nested transaction if a current transaction exists, 
    or else behave like PROPAGATION_REQUIRED.

Spring's support for nested transactions is limited to single resource transaction managers supporting the JDBC 3.0 Save Point feature.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.