Search in sources :

Example 1 with EntityWithOneToOneJoinTable

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

the class EntityWithOneToOneJoinTableTest method testHqlSelectParentWithJoin.

@Test
public void testHqlSelectParentWithJoin(SessionFactoryScope scope) {
    StatisticsImplementor statistics = scope.getSessionFactory().getStatistics();
    statistics.clear();
    scope.inTransaction(session -> {
        final EntityWithOneToOneJoinTable loaded = session.createQuery("select e from EntityWithOneToOneJoinTable e join e.other o where e.id = 1", EntityWithOneToOneJoinTable.class).uniqueResult();
        assertThat(loaded.getName(), equalTo("first"));
        assertThat(statistics.getPrepareStatementCount(), is(2L));
        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(2L));
    });
}
Also used : EntityWithOneToOneJoinTable(org.hibernate.testing.orm.domain.gambit.EntityWithOneToOneJoinTable) SimpleEntity(org.hibernate.testing.orm.domain.gambit.SimpleEntity) StatisticsImplementor(org.hibernate.stat.spi.StatisticsImplementor) Test(org.junit.jupiter.api.Test)

Example 2 with EntityWithOneToOneJoinTable

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

the class EntityWithOneToOneJoinTableTest method setUp.

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

Example 3 with EntityWithOneToOneJoinTable

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

the class EntityWithOneToOneJoinTableTest method testHqlSelectParentWithJoinFetch.

@Test
public void testHqlSelectParentWithJoinFetch(SessionFactoryScope scope) {
    StatisticsImplementor statistics = scope.getSessionFactory().getStatistics();
    statistics.clear();
    scope.inTransaction(session -> {
        final EntityWithOneToOneJoinTable loaded = session.createQuery("select e from EntityWithOneToOneJoinTable e join fetch e.other o where e.id = 1", EntityWithOneToOneJoinTable.class).uniqueResult();
        assertThat(loaded.getName(), equalTo("first"));
        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));
    });
}
Also used : EntityWithOneToOneJoinTable(org.hibernate.testing.orm.domain.gambit.EntityWithOneToOneJoinTable) SimpleEntity(org.hibernate.testing.orm.domain.gambit.SimpleEntity) StatisticsImplementor(org.hibernate.stat.spi.StatisticsImplementor) Test(org.junit.jupiter.api.Test)

Example 4 with EntityWithOneToOneJoinTable

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

the class EntityWithOneToOneJoinTableTest method testGet.

@Test
public void testGet(SessionFactoryScope scope) {
    StatisticsImplementor statistics = scope.getSessionFactory().getStatistics();
    statistics.clear();
    scope.inTransaction(session -> {
        final EntityWithOneToOneJoinTable loaded = session.get(EntityWithOneToOneJoinTable.class, 1);
        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);
        assert loaded != null;
        assertThat(loaded.getSomeInteger(), equalTo(Integer.MAX_VALUE));
    });
}
Also used : EntityWithOneToOneJoinTable(org.hibernate.testing.orm.domain.gambit.EntityWithOneToOneJoinTable) SimpleEntity(org.hibernate.testing.orm.domain.gambit.SimpleEntity) StatisticsImplementor(org.hibernate.stat.spi.StatisticsImplementor) Test(org.junit.jupiter.api.Test)

Example 5 with EntityWithOneToOneJoinTable

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

the class EntityWithOneToOneJoinTableTest method testHqlSelectParentWithImplicitJoin.

@Test
public void testHqlSelectParentWithImplicitJoin(SessionFactoryScope scope) {
    StatisticsImplementor statistics = scope.getSessionFactory().getStatistics();
    statistics.clear();
    scope.inTransaction(session -> {
        final EntityWithOneToOneJoinTable loaded = session.createQuery("select e from EntityWithOneToOneJoinTable e where e.other.id = 2", EntityWithOneToOneJoinTable.class).uniqueResult();
        assertThat(loaded.getName(), equalTo("first"));
        assertThat(statistics.getPrepareStatementCount(), is(2L));
        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(2L));
    });
}
Also used : EntityWithOneToOneJoinTable(org.hibernate.testing.orm.domain.gambit.EntityWithOneToOneJoinTable) SimpleEntity(org.hibernate.testing.orm.domain.gambit.SimpleEntity) StatisticsImplementor(org.hibernate.stat.spi.StatisticsImplementor) Test(org.junit.jupiter.api.Test)

Aggregations

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