Search in sources :

Example 1 with EntityWithManyToOneJoinTable

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

the class EntityWithManyToOneJoinTableTest method testSaveInDifferentTransactions.

@Test
public void testSaveInDifferentTransactions(SessionFactoryScope scope) {
    EntityWithManyToOneJoinTable entity = new EntityWithManyToOneJoinTable(3, "second", Integer.MAX_VALUE);
    SimpleEntity other = new SimpleEntity(4, Calendar.getInstance().getTime(), Calendar.getInstance().toInstant(), Integer.MAX_VALUE - 1, Long.MAX_VALUE, null);
    entity.setOther(other);
    scope.inTransaction(session -> {
        session.save(other);
    });
    scope.inTransaction(session -> {
        session.save(entity);
    });
    scope.inTransaction(session -> {
        final EntityWithManyToOneJoinTable loaded = session.get(EntityWithManyToOneJoinTable.class, 1);
        assert loaded != null;
        assertThat(loaded.getName(), equalTo("first"));
        assert loaded.getOther() != null;
        assertThat(loaded.getOther().getId(), equalTo(2));
    });
}
Also used : SimpleEntity(org.hibernate.testing.orm.domain.gambit.SimpleEntity) EntityWithManyToOneJoinTable(org.hibernate.testing.orm.domain.gambit.EntityWithManyToOneJoinTable) Test(org.junit.jupiter.api.Test)

Example 2 with EntityWithManyToOneJoinTable

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

the class EntityWithManyToOneJoinTableTest method testHqlSelectWithJoin.

@Test
public void testHqlSelectWithJoin(SessionFactoryScope scope) {
    final StatisticsImplementor statistics = scope.getSessionFactory().getStatistics();
    statistics.clear();
    scope.inTransaction(session -> {
        final EntityWithManyToOneJoinTable result = session.createQuery("select e from EntityWithManyToOneJoinTable e join e.other where e.id = 1", EntityWithManyToOneJoinTable.class).uniqueResult();
        assertThat(result, notNullValue());
        assertThat(result.getId(), is(1));
        assertThat(result.getName(), is("first"));
        assertThat(statistics.getPrepareStatementCount(), is(2L));
        assertThat(result.getOther().getId(), is(2));
        assertThat(result.getOther().getSomeInteger(), is(Integer.MAX_VALUE));
        assertThat(statistics.getPrepareStatementCount(), is(2L));
    });
}
Also used : EntityWithManyToOneJoinTable(org.hibernate.testing.orm.domain.gambit.EntityWithManyToOneJoinTable) StatisticsImplementor(org.hibernate.stat.spi.StatisticsImplementor) Test(org.junit.jupiter.api.Test)

Example 3 with EntityWithManyToOneJoinTable

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

the class EntityWithManyToOneJoinTableTest method testHqlSelectWithJoinFetch.

@Test
public void testHqlSelectWithJoinFetch(SessionFactoryScope scope) {
    final StatisticsImplementor statistics = scope.getSessionFactory().getStatistics();
    statistics.clear();
    scope.inTransaction(session -> {
        final EntityWithManyToOneJoinTable result = session.createQuery("select e from EntityWithManyToOneJoinTable e join fetch e.other where e.id = 1", EntityWithManyToOneJoinTable.class).uniqueResult();
        assertThat(result, notNullValue());
        assertThat(result.getId(), is(1));
        assertThat(result.getName(), is("first"));
        assertThat(statistics.getPrepareStatementCount(), is(1L));
        assertThat(result.getOther().getId(), is(2));
        assertThat(result.getOther().getSomeInteger(), is(Integer.MAX_VALUE));
        assertThat(statistics.getPrepareStatementCount(), is(1L));
    });
}
Also used : EntityWithManyToOneJoinTable(org.hibernate.testing.orm.domain.gambit.EntityWithManyToOneJoinTable) StatisticsImplementor(org.hibernate.stat.spi.StatisticsImplementor) Test(org.junit.jupiter.api.Test)

Example 4 with EntityWithManyToOneJoinTable

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

the class EntityWithManyToOneJoinTableTest method setUp.

@BeforeEach
public void setUp(SessionFactoryScope scope) {
    EntityWithManyToOneJoinTable entity = new EntityWithManyToOneJoinTable(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(entity);
        session.save(other);
    });
}
Also used : SimpleEntity(org.hibernate.testing.orm.domain.gambit.SimpleEntity) EntityWithManyToOneJoinTable(org.hibernate.testing.orm.domain.gambit.EntityWithManyToOneJoinTable) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with EntityWithManyToOneJoinTable

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

the class EntityWithManyToOneJoinTableTest method testUpdate.

@Test
public void testUpdate(SessionFactoryScope scope) {
    EntityWithManyToOneJoinTable entity = new EntityWithManyToOneJoinTable(2, "second", Integer.MAX_VALUE);
    SimpleEntity other = new SimpleEntity(4, Calendar.getInstance().getTime(), null, 100, Long.MAX_VALUE, null);
    entity.setOther(other);
    scope.inTransaction(session -> {
        session.save(other);
        session.save(entity);
    });
    SimpleEntity anOther = new SimpleEntity(5, Calendar.getInstance().getTime(), null, Integer.MIN_VALUE + 5, Long.MIN_VALUE, null);
    scope.inTransaction(session -> {
        final EntityWithManyToOneJoinTable loaded = session.get(EntityWithManyToOneJoinTable.class, 2);
        assert loaded != null;
        session.save(anOther);
        loaded.setOther(anOther);
    });
    scope.inTransaction(session -> {
        final EntityWithManyToOneJoinTable loaded = session.get(EntityWithManyToOneJoinTable.class, 2);
        assertThat(loaded.getOther(), notNullValue());
        assertThat(loaded.getOther().getId(), equalTo(5));
    });
}
Also used : SimpleEntity(org.hibernate.testing.orm.domain.gambit.SimpleEntity) EntityWithManyToOneJoinTable(org.hibernate.testing.orm.domain.gambit.EntityWithManyToOneJoinTable) Test(org.junit.jupiter.api.Test)

Aggregations

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