title: Behavior when Spring Propagation.REQUIRES_NEW is nested in a Propagation.NESTED
body: <p>I have code like so</p>
  
  <pre><code>@Transactional(propagation = Propagation.NESTED)
  @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
  public class C1 {
  ...
     public void xxx() {
        try {
           obj.someMethod();
        } catch (Exception e) {
           C2.yyy();
        }
     }
  }
  
  public class C2 {
      @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false)
      public void yyy() {
          ...
      }
  }
  </code></pre>
  
  <p>My assumption is that when <code>obj.someMethod();</code> throws a constraint violation exception <code>C2.yyy()</code> should still be able to save stuff to the DB.</p>
  
  <p>However what I see is that when <code>C2.yyy()</code> is called Postgres reports </p>
  
  <blockquote>
    <p>ERROR:  current transaction is aborted, commands ignored until end of transaction block</p>
  </blockquote>
  
  <p>Why should it do that? After all <code>C2.yyy()</code> should run in a different transaction that should be unaffected by the state of what happened in the invoking code. No?  </p>
  
  <h1>Update</h1>
  
  <p>On further debugging here is what I found - let us say the call stack is like so</p>
  
  <pre><code>@Transactional(readOnly = false, propagation = Propagation.NESTED)
  b1.m1()
         @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
         b2.m2()
                b3.m3()
                        b4.m4()
  </code></pre>
  
  <p>My assumption was that the DB code in m4() would execute in a new transaction because of the annotation on b2.m2(). But it seems the code in <a href="https://github.com/spring-projects/spring-framework/blob/4.2.x/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java#L270" rel="nofollow">TransactionAspectSupport.java</a> looks at the transaction annotation only on the current method and not on the stack. When it does not find any @transactional on m4() it assumes REQUIRES. Isn't this incorrect? </p>