Search in sources :

Example 1 with SimpleEntity

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

the class TupleTest method setUp.

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

Example 2 with SimpleEntity

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

the class EntityWithLazyBidirectionalOneToOneTest method testHqlSelectParent.

@Test
public void testHqlSelectParent(SessionFactoryScope scope) {
    StatisticsImplementor statistics = scope.getSessionFactory().getStatistics();
    statistics.clear();
    scope.inTransaction(session -> {
        final EntityWithLazyOneToOne loaded = session.createQuery("select e from EntityWithLazyOneToOne e where e.other.id = 2", EntityWithLazyOneToOne.class).uniqueResult();
        assertThat(loaded.getName(), equalTo("first"));
        assertThat(statistics.getPrepareStatementCount(), is(1L));
        SimpleEntity other = loaded.getOther();
        assertFalse(Hibernate.isInitialized(other), "The lazy association should not be initialized");
        assertThat(other, notNullValue());
        assertThat(other.getId(), equalTo(2));
        assertFalse(Hibernate.isInitialized(other), "getId() should not trigger the lazy association initialization");
        assertThat(statistics.getPrepareStatementCount(), is(1L));
        other.getSomeDate();
        assertTrue(Hibernate.isInitialized(other), "The lazy association should be initialized");
        assertThat(statistics.getPrepareStatementCount(), is(2L));
    });
}
Also used : SimpleEntity(org.hibernate.testing.orm.domain.gambit.SimpleEntity) StatisticsImplementor(org.hibernate.stat.spi.StatisticsImplementor) EntityWithLazyOneToOne(org.hibernate.testing.orm.domain.gambit.EntityWithLazyOneToOne) Test(org.junit.jupiter.api.Test)

Example 3 with SimpleEntity

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

the class EntityWithLazyBidirectionalOneToOneTest method setUp.

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

Example 4 with SimpleEntity

use of org.hibernate.testing.orm.domain.gambit.SimpleEntity 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 5 with SimpleEntity

use of org.hibernate.testing.orm.domain.gambit.SimpleEntity 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)

Aggregations

SimpleEntity (org.hibernate.testing.orm.domain.gambit.SimpleEntity)28 Test (org.junit.jupiter.api.Test)19 StatisticsImplementor (org.hibernate.stat.spi.StatisticsImplementor)15 BeforeEach (org.junit.jupiter.api.BeforeEach)8 EntityWithOneToOne (org.hibernate.testing.orm.domain.gambit.EntityWithOneToOne)7 EntityWithOneToOneJoinTable (org.hibernate.testing.orm.domain.gambit.EntityWithOneToOneJoinTable)6 EntityWithManyToOneJoinTable (org.hibernate.testing.orm.domain.gambit.EntityWithManyToOneJoinTable)5 EntityWithLazyOneToOne (org.hibernate.testing.orm.domain.gambit.EntityWithLazyOneToOne)4 BasicEntity (org.hibernate.testing.orm.domain.gambit.BasicEntity)2 EntityWithOneToOneSharingPrimaryKey (org.hibernate.testing.orm.domain.gambit.EntityWithOneToOneSharingPrimaryKey)2 Date (java.sql.Date)1 Time (java.sql.Time)1 Timestamp (java.sql.Timestamp)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 LocalTime (java.time.LocalTime)1 EntityOfBasics (org.hibernate.testing.orm.domain.gambit.EntityOfBasics)1 EntityOfLists (org.hibernate.testing.orm.domain.gambit.EntityOfLists)1 EntityOfMaps (org.hibernate.testing.orm.domain.gambit.EntityOfMaps)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1