title: No rollback only for transaction when exception occurs in submethod
body: <p>I'm using Hibernate + spring + <code>@Transactional</code> annotations to handle transactions in my application.</p>
  
  <p>Transaction manager is declared as follows:</p>
  
  <pre><code>&lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
      &lt;property name="sessionFactory" ref="sessionFactory"/&gt;
  &lt;/bean&gt;
  
  &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  </code></pre>
  
  <p>This works well in most cases, but I've found a problem where I have 2 methods, both annotated @Transactional:</p>
  
  <pre><code>package temp;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.transaction.annotation.Transactional;
  
  public class OuterTestService {
      @Autowired
      private InnerTestService innerTestService;
  
      @Transactional
      public void outerMethod() {
          try {
              innerTestService.innerTestMethod();
          } catch (RuntimeException e) {
              // some code here
          }
      }
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>package temp;
  
  import org.springframework.transaction.annotation.Transactional;
  
  public class InnerTestService {
  
      @Transactional
      public void innerTestMethod() throws RuntimeException {
          throw new RuntimeException();
      }
  }
  </code></pre>
  
  <p>When I invoke OuterTestService#outerMethod(), I get an exception</p>
  
  <pre><code>org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has been marked as rollback-only
  </code></pre>
  
  <p>As there is only one transaction (no nested transactions), the whole <code>outerTestMethod()</code>'s transaction is marked as rollback-only.</p>
  
  <p>I've found that I can easily overcome this using noRollbackFor:</p>
  
  <pre><code>package cz.csas.pdb.be.service.tempdelete;
  
  import org.springframework.transaction.annotation.Transactional;
  
  public class InnerTestService {
  
      @Transactional(noRollbackFor = RuntimeException.class)
      public void innerTestMethod() throws RuntimeException {
          throw new RuntimeException();
      }
  }
  </code></pre>
  
  <p>But this has to be explicitly used on every method. Because this error is not raised during tests (which are rollbacked), this is not acceptable.</p>
  
  <p>My question -- is there a way to automatically (eg. not explicitly for every method) set that transactions are rolled back only when an exception is raised from method which started the transaction (in this case, the <code>outerTestMethod()</code>)?</p>