Search in sources :

Example 1 with Person

use of org.hibernate.test.jdbc.Person 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();
    }
}
Also used : TransactionException(org.hibernate.TransactionException) Transaction(org.hibernate.Transaction) PersistenceException(javax.persistence.PersistenceException) SessionImplementor(org.hibernate.engine.spi.SessionImplementor) Person(org.hibernate.test.jdbc.Person) Session(org.hibernate.Session) Test(org.junit.Test)

Example 2 with Person

use of org.hibernate.test.jdbc.Person in project hibernate-orm by hibernate.

the class TransactionTimeoutTest method testTransactionTimeoutSuccess.

@Test
public void testTransactionTimeoutSuccess() {
    Session session = openSession();
    Transaction transaction = session.getTransaction();
    transaction.setTimeout(60);
    transaction.begin();
    session.persist(new Person("Lukasz", "Antoniak"));
    transaction.commit();
    session.close();
}
Also used : Transaction(org.hibernate.Transaction) Person(org.hibernate.test.jdbc.Person) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

Session (org.hibernate.Session)2 Transaction (org.hibernate.Transaction)2 Person (org.hibernate.test.jdbc.Person)2 Test (org.junit.Test)2 PersistenceException (javax.persistence.PersistenceException)1 TransactionException (org.hibernate.TransactionException)1 SessionImplementor (org.hibernate.engine.spi.SessionImplementor)1