use of org.hibernate.testing.jdbc.SQLStatementInspector in project hibernate-orm by hibernate.
the class LazyManyToOneEmbeddedIdWithToOneFKTest method testHqlJoin.
@Test
public void testHqlJoin(SessionFactoryScope scope) {
SQLStatementInspector statementInspector = (SQLStatementInspector) scope.getStatementInspector();
statementInspector.clear();
scope.inTransaction(session -> {
System system = session.createQuery("from System e join e.user where e.id = :id", System.class).setParameter("id", 1).uniqueResult();
statementInspector.assertExecutedCount(2);
statementInspector.assertNumberOfOccurrenceInQuery(0, "join", 1);
statementInspector.assertNumberOfOccurrenceInQuery(1, "join", 0);
assertFalse(Hibernate.isInitialized(system.getUser()));
assertThat(system, is(notNullValue()));
SystemUser user = system.getUser();
assertThat(user, is(notNullValue()));
});
}
use of org.hibernate.testing.jdbc.SQLStatementInspector in project hibernate-orm by hibernate.
the class ManyToOneEmbeddedIdWithLazyToOneFKTest method testHqlJoin.
@Test
public void testHqlJoin(SessionFactoryScope scope) {
SQLStatementInspector statementInspector = (SQLStatementInspector) scope.getStatementInspector();
statementInspector.clear();
scope.inTransaction(session -> {
System system = session.createQuery("from System e join e.user where e.id = :id", System.class).setParameter("id", 1).uniqueResult();
statementInspector.assertExecutedCount(2);
statementInspector.assertNumberOfOccurrenceInQuery(0, "join", 1);
statementInspector.assertNumberOfOccurrenceInQuery(1, "join", 0);
assertThat(system, is(notNullValue()));
SystemUser user = system.getUser();
assertThat(user, is(notNullValue()));
assertTrue(Hibernate.isInitialized(system.getUser()));
assertFalse(Hibernate.isInitialized(system.getUser().getPk().subsystem));
statementInspector.clear();
PK pk = system.getUser().getPk();
assertThat(pk.username, is("Fab"));
Subsystem subsystem = pk.getSubsystem();
assertThat(subsystem.getId(), is(2));
assertThat(subsystem.getDescription(), is("sub1"));
statementInspector.assertExecutedCount(1);
statementInspector.assertNumberOfOccurrenceInQuery(0, "join", 0);
});
}
use of org.hibernate.testing.jdbc.SQLStatementInspector in project hibernate-orm by hibernate.
the class ManyToOneEmbeddedIdWithLazyToOneFKTest method testGet.
@Test
public void testGet(SessionFactoryScope scope) {
SQLStatementInspector statementInspector = (SQLStatementInspector) scope.getStatementInspector();
statementInspector.clear();
scope.inTransaction(session -> {
System system = session.get(System.class, 1);
assertThat(system, is(notNullValue()));
assertThat(system.getId(), is(1));
assertTrue(Hibernate.isInitialized(system.getUser()));
PK pk = system.getUser().getPk();
assertFalse(Hibernate.isInitialized(pk.subsystem));
SystemUser user = system.getUser();
assertThat(user, is(notNullValue()));
statementInspector.assertExecutedCount(1);
statementInspector.assertNumberOfOccurrenceInQuery(0, "join", 1);
statementInspector.clear();
assertThat(pk.username, is("Fab"));
Subsystem subsystem = pk.getSubsystem();
assertThat(subsystem.getId(), is(2));
assertThat(subsystem.getDescription(), is("sub1"));
statementInspector.assertExecutedCount(1);
statementInspector.assertNumberOfOccurrenceInQuery(0, "join", 0);
});
}
use of org.hibernate.testing.jdbc.SQLStatementInspector in project hibernate-orm by hibernate.
the class IdClassTest method testHql.
@Test
public void testHql(SessionFactoryScope scope) {
SQLStatementInspector statementInspector = (SQLStatementInspector) scope.getStatementInspector();
statementInspector.clear();
scope.inTransaction(session -> {
PK pk = new PK("Linux", "admin", 1);
SystemUser systemUser = session.createQuery("from SystemUser s where s.id = :id", SystemUser.class).setParameter("id", pk).getSingleResult();
assertThat(systemUser.getName(), is("Andrea"));
assertThat(systemUser.getSubsystem(), is("Linux"));
assertThat(systemUser.getUsername(), is("admin"));
assertThat(systemUser.getRegistrationId(), is(1));
statementInspector.assertExecutedCount(1);
statementInspector.assertNumberOfOccurrenceInQuery(0, "join", 0);
});
statementInspector.clear();
scope.inTransaction(session -> {
SystemUser systemUser = session.createQuery("from SystemUser s where s.username = :username", SystemUser.class).setParameter("username", "admin").getSingleResult();
assertThat(systemUser.getName(), is("Andrea"));
assertThat(systemUser.getSubsystem(), is("Linux"));
assertThat(systemUser.getUsername(), is("admin"));
assertThat(systemUser.getRegistrationId(), is(1));
statementInspector.assertExecutedCount(1);
statementInspector.assertNumberOfOccurrenceInQuery(0, "join", 0);
});
}
use of org.hibernate.testing.jdbc.SQLStatementInspector in project hibernate-orm by hibernate.
the class IdClassWithEagerManyToOneTest method testGet.
@Test
public void testGet(SessionFactoryScope scope) {
SQLStatementInspector statementInspector = (SQLStatementInspector) scope.getStatementInspector();
statementInspector.clear();
scope.inTransaction(session -> {
PK pk = new PK(new Subsystem("1", "Linux2"), "admin");
SystemUser systemUser = session.get(SystemUser.class, pk);
assertThat(systemUser.getName(), is("Andrea"));
Subsystem subsystem = systemUser.getSubsystem();
statementInspector.assertExecutedCount(1);
statementInspector.assertNumberOfOccurrenceInQuery(0, "join", 1);
statementInspector.clear();
assertTrue(Hibernate.isInitialized(subsystem));
assertThat(subsystem.getId(), is("1"));
assertThat(subsystem.getDescription(), is("Linux"));
assertThat(systemUser.getUsername(), is("admin"));
statementInspector.assertExecutedCount(0);
});
}
Aggregations