Search in sources :

Example 1 with AbstractSharedSessionContract

use of org.hibernate.internal.AbstractSharedSessionContract in project hibernate-orm by hibernate.

the class LazyLoadingLoggingTest method testDisconnect.

@Test
@TestForIssue(jiraKey = "HHH-12484")
public void testDisconnect(SessionFactoryScope scope) {
    scope.inTransaction(session -> {
        Address address = session.load(Address.class, 1L);
        AbstractSharedSessionContract sessionContract = (AbstractSharedSessionContract) session;
        sessionContract.getJdbcCoordinator().close();
        try {
            address.getClient().getName();
            fail("Should throw LazyInitializationException");
        } catch (LazyInitializationException expected) {
            assertEquals("could not initialize proxy " + "[org.hibernate.orm.test.lazyload.LazyLoadingLoggingTest$Address#1] " + "- the owning Session is disconnected", expected.getMessage());
        }
        session.getTransaction().markRollbackOnly();
    });
}
Also used : AbstractSharedSessionContract(org.hibernate.internal.AbstractSharedSessionContract) LazyInitializationException(org.hibernate.LazyInitializationException) Test(org.junit.jupiter.api.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

LazyInitializationException (org.hibernate.LazyInitializationException)1 AbstractSharedSessionContract (org.hibernate.internal.AbstractSharedSessionContract)1 TestForIssue (org.hibernate.testing.TestForIssue)1 Test (org.junit.jupiter.api.Test)1