title: Why does not commit transaction of Requires_New?
body: <p>I am working on SAP java application server with EJB 3.0</p>
  <p>I want to database insert one by one. Because I have too much data and I have to divide data. So I made try test code and it did work but it did not work as I want.</p>
  <p>I want to create a new transaction for each part and of course at the end method(transaction) should be commit.</p>
  <p>Sample code is below;</p>
  <pre><code>package com.transaction.jobs;
  
  import javax.ejb.Local;
  
  /**
   *
   * @author muratdemir
   */
  @Local
  public interface TestTransactionLocal {
  
      public void onStart();
  
      public void insertObject(int i);
  }
  </code></pre>
  <p>and</p>
  <pre><code>package com.transaction.jobs;
  
  import com.transaction.service.DatabaseServiceLocal;
  import com.transaction.entity.Item;
  import com.transaction.entity.Logger;
  import java.util.Date;
  import javax.annotation.Resource;
  import javax.ejb.EJB;
  import javax.ejb.EJBContext;
  import javax.ejb.Stateless;
  import javax.ejb.TransactionAttribute;
  import javax.ejb.TransactionAttributeType;
  import javax.ejb.TransactionManagement;
  import javax.ejb.TransactionManagementType;
  
  /**
   *
   * @author muratdemir
   */
  @Stateless
  @TransactionManagement(TransactionManagementType.CONTAINER)
  public class TestTransactionService implements TestTransactionLocal {
  
      @EJB
      DatabaseServiceLocal databaseService;
  
      @Resource
      EJBContext context;
  
      @TransactionAttribute(TransactionAttributeType.REQUIRED)
      public void onStart() {
          try {
              System.out.println(&quot;START&quot;);
  
              Logger log1 = new Logger(new Date(), &quot;&gt;&gt;&gt;T1 commiting&quot;);
              databaseService.create(log1);
  
              System.out.println(&quot;&gt;&gt;&gt;T1 committing&quot;);
  
              Thread.sleep(5000);
  
              for (int i = 1; i &lt; 10; i++) {
                  System.out.println(&quot;Call new Transaction&quot;);
  
                  insertObject(i);
  
                  Thread.sleep(2000);
              }
  
              Thread.sleep(5000);
  
              Logger log2 = new Logger(new Date(), &quot;&lt;&lt;&lt;T1 commiting&quot;);
  
              databaseService.create(log2);
  
              System.out.println(&quot;&lt;&lt;&lt;T1 committing&quot;);
  
              Thread.sleep(5000);
              System.out.println(&quot;END&quot;);
          } catch (Exception e) {
              e.printStackTrace();
              context.setRollbackOnly();
          }
  
      }
  
      @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
      public void insertObject(int i) {
          try {
              System.out.println(&quot;New Transaction Start i:&quot; + i);
  
              Item item = new Item(new Date(), &quot;Name_&quot; + i);
  
              databaseService.create(item);
  
              System.out.println(&quot;commit transaction: &quot; + i);
          } catch (Exception e) {
              e.printStackTrace();
              context.setRollbackOnly();
          }
      }
  
  }
  </code></pre>
  <p>The insertObject(Requires_New) function is work but it did not commit. It waiting for commit other onStart(REQUIRED) function. If mytimer function is end, the insert function makes all commit.</p>
  <p>Why new transaction is did not committed?</p>
  <p><strong>Note:</strong> If I change transaction attribute of the onStart function REQUIRED to NOT_SUPPORTED it works as I want. Why it works this way?</p>