Search in sources :

Example 16 with TransactionException

use of org.hibernate.TransactionException in project hibernate-orm by hibernate.

the class TransactionImpl method rollback.

@Override
public void rollback() {
    if (jpaCompliance.isJpaTransactionComplianceEnabled()) {
        if (!isActive()) {
            throw new IllegalStateException("JPA compliance dictates throwing IllegalStateException when #rollback " + "is called on non-active transaction");
        }
    }
    TransactionStatus status = getStatus();
    if (status == TransactionStatus.ROLLED_BACK || status == TransactionStatus.NOT_ACTIVE) {
        // Allow rollback() calls on completed transactions, just no-op.
        LOG.debug("rollback() called on an inactive transaction");
        return;
    }
    if (!status.canRollback()) {
        throw new TransactionException("Cannot rollback transaction in current status [" + status.name() + "]");
    }
    LOG.debug("rolling back");
    if (status != TransactionStatus.FAILED_COMMIT || allowFailedCommitToPhysicallyRollback()) {
        internalGetTransactionDriverControl().rollback();
    }
}
Also used : TransactionException(org.hibernate.TransactionException) TransactionStatus(org.hibernate.resource.transaction.spi.TransactionStatus)

Aggregations

TransactionException (org.hibernate.TransactionException)16 SystemException (javax.transaction.SystemException)6 Test (org.junit.Test)5 Session (org.hibernate.Session)4 SQLException (java.sql.SQLException)3 Transaction (org.hibernate.Transaction)2 SessionImplementor (org.hibernate.engine.spi.SessionImplementor)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 FutureTask (java.util.concurrent.FutureTask)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 PersistenceException (javax.persistence.PersistenceException)1 Query (javax.persistence.Query)1 TransactionManager (javax.transaction.TransactionManager)1 AssertionFailure (org.hibernate.AssertionFailure)1 EmptyInterceptor (org.hibernate.EmptyInterceptor)1 Interceptor (org.hibernate.Interceptor)1 LazyInitializationException (org.hibernate.LazyInitializationException)1 BeforeTransactionCompletionProcess (org.hibernate.action.spi.BeforeTransactionCompletionProcess)1 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)1