Announcement Announcement Module
Collapse
No announcement yet.
FOLLOW ON: Spring 2.5 - Transaction not rolling back for two separate method calls Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • FOLLOW ON: Spring 2.5 - Transaction not rolling back for two separate method calls

    Worried that I am trashing all over somebody elses forum entry, so I have created as new.

    RE: http://forum.springframework.org/new...ote=1&p=194893

    If that is the case, what is the point of the REQUIRED propagation level, as for every method marked as Transactional a new pysical Transaction is being created.

    Also, why does the Spring documentation show one physical transaction:

    http://static.springframework.org/sp...ation-required


    I am very confused as I have tests explicitly for this behaviour.

    Thanks

  • #2
    If you have 2 methods annotated with REQUIRED and method1 calls method2 the transaciton is propagated. If method1 wouldn't be transactional method2 would start a new transaction. Which is also quite explicitly shown in the graphical representation.

    Code:
    public class Class1 {
    
    private Class2 instance2;
    
    @Transactional
    public void method1() {
      instance2.method2();
      some other stuff.
    }
    } 
    
    public class Class2 {
    
    @Transaction(Propagation=REQUIRED)
    public void method2(){
      //some stuff.
    }
    }
    Code:
    Caller -> instance1.method1() -> instance2.method2();
    In your case you are doing

    Code:
         
    Caller -> manager.insert();
    Caller -> manager.update();
    Simpy said your transaction boundaries are wrong. If insert and update need to be in 1 transaction then put them in 1 method which first calls insert then update and give it some meaningful name (createNewOrderReport or whatever those 2 method calls do).

    Now if method1 is REQUIRED and method2 is REQUIRES_NEW a new transaction would be started and committed right after method2 finishes, and the transaction of method1 is continued.

    With @Transactional you are defining your transaction boundary for THAT specific method. If we wouldn't do that then WHEN do we commit a transaction? At random?
    Last edited by Marten Deinum; Aug 5th, 2008, 08:02 AM.

    Comment


    • #3
      Thanks for the explanation.

      In my case, we use this type of propagation when doing

      Code:
      Caller -> instance1.method1() -> instance2.method2();
      Completely take your point regarding the neccessity for a Transactional service method when doing:

      Code:
      Caller -> manager.insert();
      Caller -> manager.update();
      Regards

      Comment

      Working...
      X