use of org.hibernate.TransactionException in project hibernate-orm by hibernate.
the class TransactionTimeoutTest method testTransactionTimeoutFailure.
@Test
public void testTransactionTimeoutFailure() throws InterruptedException {
Session session = openSession();
try {
Transaction transaction = session.getTransaction();
transaction.setTimeout(1);
assertEquals(-1, ((SessionImplementor) session).getJdbcCoordinator().determineRemainingTransactionTimeOutPeriod());
transaction.begin();
Thread.sleep(1000);
session.persist(new Person("Lukasz", "Antoniak"));
transaction.commit();
} catch (TransactionException e) {
// expected
} catch (PersistenceException e) {
assertTyping(TransactionException.class, e.getCause());
} finally {
session.close();
}
}
use of org.hibernate.TransactionException in project hibernate-orm by hibernate.
the class InterceptorTest method testPrepareStatementFaultIntercept.
public void testPrepareStatementFaultIntercept() {
final Interceptor interceptor = new EmptyInterceptor() {
@Override
public String onPrepareStatement(String sql) {
return null;
}
};
Session s = openSession(interceptor);
try {
Transaction t = s.beginTransaction();
User u = new User("Kinga", "Mroz");
s.persist(u);
t.commit();
} catch (TransactionException e) {
assertTrue(e.getCause() instanceof AssertionFailure);
} finally {
s.close();
}
}
use of org.hibernate.TransactionException in project hibernate-orm by hibernate.
the class AbstractBasicJtaTestScenarios method testMarkRollbackOnly.
@Test
@SuppressWarnings("EmptyCatchBlock")
public void testMarkRollbackOnly() throws Exception {
JtaTransactionCoordinatorImpl transactionCoordinator = new JtaTransactionCoordinatorImpl(transactionCoordinatorBuilder, owner, true, JtaPlatformStandardTestingImpl.INSTANCE, preferUserTransactions(), true);
// pre conditions
final TransactionManager tm = JtaPlatformStandardTestingImpl.INSTANCE.transactionManager();
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
assertEquals(TransactionStatus.NOT_ACTIVE, transactionCoordinator.getTransactionDriverControl().getStatus());
transactionCoordinator.getTransactionDriverControl().begin();
assertEquals(TransactionStatus.ACTIVE, transactionCoordinator.getTransactionDriverControl().getStatus());
transactionCoordinator.getTransactionDriverControl().markRollbackOnly();
assertEquals(TransactionStatus.MARKED_ROLLBACK, transactionCoordinator.getTransactionDriverControl().getStatus());
try {
transactionCoordinator.getTransactionDriverControl().commit();
} catch (TransactionException expected) {
} finally {
assertEquals(TransactionStatus.NOT_ACTIVE, transactionCoordinator.getTransactionDriverControl().getStatus());
}
}
use of org.hibernate.TransactionException in project hibernate-orm by hibernate.
the class JtaTransactionAdapterTransactionManagerImpl method rollback.
@Override
public void rollback() {
try {
if (initiator) {
initiator = false;
log.trace("Calling TransactionManager#rollback");
transactionManager.rollback();
log.trace("Called TransactionManager#rollback");
} else {
markRollbackOnly();
}
} catch (Exception e) {
throw new TransactionException("JTA TransactionManager#rollback failed", e);
}
}
use of org.hibernate.TransactionException in project hibernate-orm by hibernate.
the class JtaTransactionAdapterUserTransactionImpl method commit.
@Override
public void commit() {
try {
if (initiator) {
initiator = false;
log.trace("Calling UserTransaction#commit");
userTransaction.commit();
log.trace("Called UserTransaction#commit");
} else {
log.trace("Skipping TransactionManager#commit due to not being initiator");
}
} catch (Exception e) {
throw new TransactionException("JTA UserTransaction#commit failed", e);
}
}
Aggregations