title: EJB TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) doesn'
body: <p>I encountered an odd EJB transaction attribute problem. The @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) doesn't start a new transaction as expected.</p>
  
  <p>I am using EJB 3 with Weblogic.</p>
  
  <p>Here is the pseudo code:</p>
  
  <pre><code>@Stateless
  public class EJB1 implements IEJB1
  {
     @EJB 
     private IEJB2 ejb2;
  
     @Override
     public void method1()
     {
       for (i=0; i&lt;N; i++) {
           ejb2.method2();
        }
     }
  }
  
  @Stateless
  public class EJB2 implements IEJB2
  {
     @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
     public void method2()
     {
       DBpersist();
     }
  }
  </code></pre>
  
  <p>Since I specified TransactionAttributeType.REQUIRES_NEW for EJB2.method2, I expect a new transaction to be created for methood2. But during testing I found out there's no new transaction created for method2, instead method2 has the same transaction as EJB1.method1. I used Weblogic's API to log the transaction info.</p>
  
  <p>I then made the following code change:</p>
  
  <pre><code>@Override
  @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED
  public void method1()
  {    
      for (i=0; i&lt;N; i++) {
      ejb2.method2();
      }
  }
  </code></pre>
  
  <p>This way it forced the container to create a new transaction for EJB2.method2.</p>
  
  <p>But I don't understand why the container didn't create new transaction for EJB2.method2 when I had default TransactionAttributeType for EJB1.method1 (by not specifying any TransactionAttributeType) and TransactionAttributeType=REQUIRES_NEW for EJB2.method2.</p>
  
  <p>I searched the existing questions related to this question. But all I found were the cases when you call a private method(with REQUIRES_NEW) from another private method within the same EJB, the container won't start a new transaction unless you call it through the EJB interface. This is not my case.</p>