| Steve Ebersole, I have created a PR, when the EntityManager#getTransaction() is called on a closed EntityManager a Transaction is returned and the only method you can call on it, without having an exception, are isActive. This is the same behaviour we have in 5.0 and 5.1. What I do not like it is the need to enable the JPA_TRANSACTION_COMPLIANCE in order to have the same behaviour for the following cases
@Test(expected = IllegalStateException.class)
public void getTransactionOnClosedEntityManagerCallGetRollBackOnly() {
EntityManager em = createEntityManager();
em.close();
em.getTransaction().getRollbackOnly();
}
@Test(expected = IllegalStateException.class)
public void getTransactionOnClosedEntityManagerCallGetRollBackOnly_2() {
EntityManager em = createEntityManager();
EntityTransaction transaction = em.getTransaction();
em.close();
transaction.getRollbackOnly();
}
@Test(expected = IllegalStateException.class)
public void getTransactionOnClosedEntityManagerCallRollBack() {
EntityManager em = createEntityManager();
em.close();
em.getTransaction().rollback();
}
@Test(expected = IllegalStateException.class)
public void getTransactionOnClosedEntityManagerCallRollBack_2() {
EntityManager em = createEntityManager();
EntityTransaction transaction = em.getTransaction();
em.close();
transaction.rollback();
}
and
@Test(expected = IllegalStateException.class)
public void getTransactionOnClosedEntityManagerCallSetRollBackOnly() {
EntityManager em = createEntityManager();
em.close();
em.getTransaction().setRollbackOnly();
}
@Test(expected = IllegalStateException.class)
public void getTransactionOnClosedEntityManagerCallSetRollBackOnly_2() {
EntityManager em = createEntityManager();
EntityTransaction transaction = em.getTransaction();
em.close();
transaction.setRollbackOnly();
}
|