HHH-10807 - Fix flush operation to work when transaction marked for rollback.
This commit is contained in:
parent
e7933ababb
commit
1bc2f7c79c
|
@ -342,9 +342,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
|
|||
|
||||
@Override
|
||||
public boolean isTransactionInProgress() {
|
||||
return !isClosed()
|
||||
&& transactionCoordinator.isJoined()
|
||||
&& transactionCoordinator.getTransactionDriverControl().getStatus() == TransactionStatus.ACTIVE;
|
||||
return !isClosed() && transactionCoordinator.isTransactionActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -84,8 +84,7 @@ public class JdbcResourceLocalTransactionCoordinatorImpl implements TransactionC
|
|||
|
||||
@Override
|
||||
public boolean isJoined() {
|
||||
return physicalTransactionDelegate != null && physicalTransactionDelegate.getStatus() == TransactionStatus.ACTIVE;
|
||||
|
||||
return physicalTransactionDelegate != null && getTransactionDriverControl().isActive( true );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -95,6 +95,14 @@ public interface TransactionCoordinator {
|
|||
|
||||
int getTimeOut();
|
||||
|
||||
default boolean isTransactionActive() {
|
||||
return isTransactionActive( true );
|
||||
}
|
||||
|
||||
default boolean isTransactionActive(boolean isMarkedRollbackConsideredActive) {
|
||||
return isJoined() && getTransactionDriverControl().isActive( isMarkedRollbackConsideredActive );
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the means for "local transactions" (as transaction drivers) to control the
|
||||
* underlying "physical transaction" currently associated with the TransactionCoordinator.
|
||||
|
|
|
@ -11,6 +11,7 @@ import javax.persistence.EntityManager;
|
|||
import javax.persistence.LockModeType;
|
||||
import javax.persistence.OptimisticLockException;
|
||||
import javax.persistence.PersistenceException;
|
||||
import javax.persistence.Query;
|
||||
import javax.persistence.RollbackException;
|
||||
import javax.persistence.TransactionRequiredException;
|
||||
|
||||
|
@ -293,4 +294,23 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase
|
|||
Book.class
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetRollbackOnlyAndFlush() throws Exception {
|
||||
Book book = new Book();
|
||||
book.name = "The jungle book";
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
em.getTransaction().setRollbackOnly();
|
||||
em.persist( book );
|
||||
em.flush();
|
||||
em.getTransaction().rollback();
|
||||
em.getTransaction().begin();
|
||||
Query query = em.createQuery( "SELECT b FROM Book b WHERE b.name = :name" );
|
||||
query.setParameter( "name", book.name );
|
||||
assertEquals( 0, query.getResultList().size() );
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue