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));
});
}
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));
});
}
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));
});
}
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);
});
}
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));
});
}
Aggregations