title: Glassfish: JTA/JPA transaction not rolling back
body: <p>I am running Glassfish 3.1.1 with an Oracle database and have run into an issue with transactions not rolling back, but only on one specific environment so far.  The same application works as expected on other machines.  However, two separate Glassfish domains on the same machine are impacted.</p>
  
  <p>Within the affected environment, I have similar results with both a container-managed transactions (CMT) inside an EJB that throws a RuntimeException, and a bean-managed transaction (BMT) with <code>UserTransaction#rollback()</code>.</p>
  
  <p>In both cases, the underlying issue appears to be that the JDBC connection is somehow still set with autoCommit = true even though there is a JTA transaction in progress.</p>
  
  <p>My EJB/CMT test looks like this:</p>
  
  <pre><code>@Named
  @Stateless
  public class TransactionTest { 
  
    @PersistenceContext
    EntityManager entityManager;
  
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void rollbackTest() {
      Foo foo = new Foo();
      entityManager.persist(foo);
      entityManager.flush();
  
      throw new RuntimeException("should be rolled back");
    }
  }
  </code></pre>
  
  <p>and my BMT/UserTransaction test is like this:</p>
  
  <pre><code>public void rollbackUtxTest() throws Exception {
      utx.begin();
  
      Foo foo = new Foo();
      entityManager.persist(foo);
      entityManager.flush();
  
      utx.rollback();   
  }
  </code></pre>
  
  <p>When I call either method, the <code>INSERT INTO FOO</code> is committed, even though the transactions were rolled back.  </p>
  
  <p>What am I missing - perhaps I don't have my connection pool / datasource is not set up right?  </p>
  
  <p>I'm using OracleConnectionPoolDataSource as the datasource class name.  Is there something I need to do to ensure my database connections participate in JTA transactions?</p>
  
  <p><strong>UPDATE 1</strong> I originally thought this was an issue with <code>OracleConnectionPoolDataSource</code> but it turned out it was not correlated.  The same exact pool configuration works on one environment but not the other.</p>
  
  <p><strong>UPDATE 2</strong> Clarified that this is not specifically an EJB/CMT issue, but a general JTA issue.</p>
  
  <p><strong>UPDATE 3</strong> added info about JDBC autocommit.  Confirmed that persistence.xml is correct.</p>