Search in sources :

Example 1 with EntityWithOneToOneSharingPrimaryKey

use of org.hibernate.testing.orm.domain.gambit.EntityWithOneToOneSharingPrimaryKey in project hibernate-orm by hibernate.

the class EntityWithOneToOneSharingPrimaryKeyTest method testGet.

@Test
public void testGet(SessionFactoryScope scope) {
    StatisticsImplementor statistics = scope.getSessionFactory().getStatistics();
    statistics.clear();
    scope.inTransaction(session -> {
        final EntityWithOneToOneSharingPrimaryKey loaded = session.get(EntityWithOneToOneSharingPrimaryKey.class, 2);
        assertThat(statistics.getPrepareStatementCount(), is(1L));
        assertThat(loaded, notNullValue());
        assertThat(loaded.getName(), equalTo("first"));
        SimpleEntity other = loaded.getOther();
        assertTrue(Hibernate.isInitialized(other));
        assertThat(other, notNullValue());
        assertThat(other.getId(), equalTo(2));
        assertThat(statistics.getPrepareStatementCount(), is(1L));
    });
    scope.inTransaction(session -> {
        final SimpleEntity loaded = session.get(SimpleEntity.class, 2);
        assertThat(loaded, notNullValue());
    });
}
Also used : SimpleEntity(org.hibernate.testing.orm.domain.gambit.SimpleEntity) StatisticsImplementor(org.hibernate.stat.spi.StatisticsImplementor) EntityWithOneToOneSharingPrimaryKey(org.hibernate.testing.orm.domain.gambit.EntityWithOneToOneSharingPrimaryKey) Test(org.junit.jupiter.api.Test)

Example 2 with EntityWithOneToOneSharingPrimaryKey

use of org.hibernate.testing.orm.domain.gambit.EntityWithOneToOneSharingPrimaryKey in project hibernate-orm by hibernate.

the class EntityWithOneToOneSharingPrimaryKeyTest method testHqlSelectFetchWithJoin.

@Test
public void testHqlSelectFetchWithJoin(SessionFactoryScope scope) {
    StatisticsImplementor statistics = scope.getSessionFactory().getStatistics();
    statistics.clear();
    scope.inTransaction(session -> {
        final EntityWithOneToOneSharingPrimaryKey value = session.createQuery("select e from EntityWithOneToOneSharingPrimaryKey e join fetch e.other t where t.id = 2", EntityWithOneToOneSharingPrimaryKey.class).uniqueResult();
        assertThat(value.getName(), equalTo("first"));
        assertThat(statistics.getPrepareStatementCount(), is(1L));
        assertTrue(Hibernate.isInitialized(value.getOther()));
    });
}
Also used : StatisticsImplementor(org.hibernate.stat.spi.StatisticsImplementor) EntityWithOneToOneSharingPrimaryKey(org.hibernate.testing.orm.domain.gambit.EntityWithOneToOneSharingPrimaryKey) Test(org.junit.jupiter.api.Test)

Example 3 with EntityWithOneToOneSharingPrimaryKey

use of org.hibernate.testing.orm.domain.gambit.EntityWithOneToOneSharingPrimaryKey in project hibernate-orm by hibernate.

the class EntityWithOneToOneSharingPrimaryKeyTest method setUp.

@BeforeEach
public void setUp(SessionFactoryScope scope) {
    SimpleEntity other = new SimpleEntity(2, Calendar.getInstance().getTime(), null, Integer.MAX_VALUE, Long.MAX_VALUE, null);
    EntityWithOneToOneSharingPrimaryKey entity = new EntityWithOneToOneSharingPrimaryKey(other.getId(), "first", Integer.MAX_VALUE);
    entity.setOther(other);
    scope.inTransaction(session -> {
        session.save(other);
        session.save(entity);
    });
}
Also used : SimpleEntity(org.hibernate.testing.orm.domain.gambit.SimpleEntity) EntityWithOneToOneSharingPrimaryKey(org.hibernate.testing.orm.domain.gambit.EntityWithOneToOneSharingPrimaryKey) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with EntityWithOneToOneSharingPrimaryKey

use of org.hibernate.testing.orm.domain.gambit.EntityWithOneToOneSharingPrimaryKey in project hibernate-orm by hibernate.

the class EntityWithOneToOneSharingPrimaryKeyTest method testHqlSelectWithJoin.

@Test
public void testHqlSelectWithJoin(SessionFactoryScope scope) {
    StatisticsImplementor statistics = scope.getSessionFactory().getStatistics();
    statistics.clear();
    scope.inTransaction(session -> {
        final EntityWithOneToOneSharingPrimaryKey value = session.createQuery("select e from EntityWithOneToOneSharingPrimaryKey e join e.other t where t.id = 2", EntityWithOneToOneSharingPrimaryKey.class).uniqueResult();
        assertThat(value.getName(), equalTo("first"));
        assertThat(statistics.getPrepareStatementCount(), is(2L));
        assertTrue(Hibernate.isInitialized(value.getOther()));
    });
}
Also used : StatisticsImplementor(org.hibernate.stat.spi.StatisticsImplementor) EntityWithOneToOneSharingPrimaryKey(org.hibernate.testing.orm.domain.gambit.EntityWithOneToOneSharingPrimaryKey) Test(org.junit.jupiter.api.Test)

Example 5 with EntityWithOneToOneSharingPrimaryKey

use of org.hibernate.testing.orm.domain.gambit.EntityWithOneToOneSharingPrimaryKey in project hibernate-orm by hibernate.

the class EntityWithOneToOneSharingPrimaryKeyTest method testHqlSelectWithImplicitJoin.

@Test
public void testHqlSelectWithImplicitJoin(SessionFactoryScope scope) {
    StatisticsImplementor statistics = scope.getSessionFactory().getStatistics();
    statistics.clear();
    scope.inTransaction(session -> {
        final EntityWithOneToOneSharingPrimaryKey value = session.createQuery("select e from EntityWithOneToOneSharingPrimaryKey e where e.other.id = 2", EntityWithOneToOneSharingPrimaryKey.class).uniqueResult();
        assertThat(value.getName(), equalTo("first"));
        assertThat(statistics.getPrepareStatementCount(), is(2L));
        assertTrue(Hibernate.isInitialized(value.getOther()));
    });
}
Also used : StatisticsImplementor(org.hibernate.stat.spi.StatisticsImplementor) EntityWithOneToOneSharingPrimaryKey(org.hibernate.testing.orm.domain.gambit.EntityWithOneToOneSharingPrimaryKey) Test(org.junit.jupiter.api.Test)

Aggregations

EntityWithOneToOneSharingPrimaryKey (org.hibernate.testing.orm.domain.gambit.EntityWithOneToOneSharingPrimaryKey)5 StatisticsImplementor (org.hibernate.stat.spi.StatisticsImplementor)4 Test (org.junit.jupiter.api.Test)4 SimpleEntity (org.hibernate.testing.orm.domain.gambit.SimpleEntity)2 BeforeEach (org.junit.jupiter.api.BeforeEach)1