title: Understanding Spring transactions - What happens when a transactional method calls another transactional method?
body: <p>Just to understand the workings of Spring transactions I want to know what happens in the following case where one method marked as <code>@Transactional</code> calls another method marked as <code>@Transactional</code>.</p>
  
  <p>Assume a the configuration uses all default settings.</p>
  
  <pre><code>@Service("myService")
  @Transactional
  public MyService{
     public void myServiceMethod(){
        myDAO.getSomeDBObjects();
     }
  }
  
  @Repository("myDAO")
  @Transactional
  public MyDAOWithUsesBeyondMyService{
     public void getSomeDBObjects(){...}
  }
  </code></pre>
  
  <p>Now if I were to enter <code>MyService.myServiceMethod()</code> it would clearly start a transaction. Then, upon drilling into <code>myDAO.getSomeDBObjects()</code> what would happen? Would the fact that a transaction already exist cause no new transaction to be born, or am I creating two transactions here?</p>
  
  <p>The documentation (quoted below) on Propagation seems to cover this, but I'd like to verify my understanding, it was a little much for my virgin brain to comprehend all at once.</p>
  
  <blockquote>
    <p><strong>Propagation</strong>: Typically, all code
    executed within a transaction scope
    will run in that transaction. However,
    you have the option of specifying the
    behavior in the event that a
    transactional method is executed when
    a transaction context already exists.
    For example, code can continue running
    in the existing transaction (the
    common case); or the existing
    transaction can be suspended and a new
    transaction created. Spring offers all
    of the transaction propagation options
    familiar from EJB CMT. To read about
    the semantics of transaction
    propagation in Spring, see Section
    10.5.7, “Transaction propagation”.</p>
  </blockquote>