use of org.hibernate.testing.jdbc.SQLStatementInspector in project hibernate-orm by hibernate.
the class NotOptionalManyToOneTest method testInnerJoinIsUsed.
@Test
public void testInnerJoinIsUsed(SessionFactoryScope scope) {
SQLStatementInspector statementInspector = (SQLStatementInspector) scope.getStatementInspector();
statementInspector.clear();
scope.inTransaction(session -> {
session.get(Parent.class, 2);
statementInspector.assertNumberOfJoins(0, SqlAstJoinType.INNER, 1);
});
}
use of org.hibernate.testing.jdbc.SQLStatementInspector in project hibernate-orm by hibernate.
the class EntityGraphWithFetchAnnotationTest method testWithEntityGraph.
@Test
@TestForIssue(jiraKey = "HHH-10485")
void testWithEntityGraph(SessionFactoryScope scope) {
SQLStatementInspector statementInspector = (SQLStatementInspector) scope.getStatementInspector();
statementInspector.clear();
scope.inTransaction(session -> {
EntityManager entityManager = session.unwrap(EntityManager.class);
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Order> criteriaQuery = criteriaBuilder.createQuery(Order.class);
criteriaQuery.from(Order.class);
EntityGraph<Order> entityGraph = entityManager.createEntityGraph(Order.class);
entityGraph.addAttributeNodes("products");
entityManager.createQuery(criteriaQuery).setFirstResult(10).setMaxResults(20).setHint(GraphSemantic.FETCH.getJpaHintName(), entityGraph).getResultList();
statementInspector.assertExecutedCount(1);
String sql = statementInspector.getSqlQueries().get(0);
assertThat(sql, containsString("left join"));
});
}
use of org.hibernate.testing.jdbc.SQLStatementInspector in project hibernate-orm by hibernate.
the class LoadAndFetchGraphTest method testQueryByIdWithLoadGraph.
@Test
void testQueryByIdWithLoadGraph(SessionFactoryScope scope) {
SQLStatementInspector statementInspector = (SQLStatementInspector) scope.getStatementInspector();
statementInspector.clear();
scope.inTransaction(session -> {
EntityManager entityManager = session.unwrap(EntityManager.class);
EntityGraph<CEntity> entityGraph = entityManager.createEntityGraph(CEntity.class);
entityGraph.addAttributeNodes("a", "b");
entityGraph.addSubgraph("dList").addAttributeNodes("e");
TypedQuery<CEntity> query = entityManager.createQuery("select c from CEntity as c where c.id = :cid ", CEntity.class);
query.setHint(GraphSemantic.LOAD.getJpaHintName(), entityGraph);
query.setParameter("cid", 1);
CEntity cEntity = query.getSingleResult();
assertThat(cEntity.getA(), isInitialized());
assertThat(cEntity.getB(), isInitialized());
assertThat(cEntity.getC(), isNotInitialized());
assertThat(cEntity.getDList(), isInitialized());
cEntity.getDList().forEach(dEntity -> assertThat(dEntity.getE(), isInitialized()));
assertThat(statementInspector.getSqlQueries(), hasSize(1));
});
}
use of org.hibernate.testing.jdbc.SQLStatementInspector in project hibernate-orm by hibernate.
the class LoadAndFetchGraphTest method testQueryById.
@Test
void testQueryById(SessionFactoryScope scope) {
SQLStatementInspector statementInspector = (SQLStatementInspector) scope.getStatementInspector();
statementInspector.clear();
scope.inTransaction(session -> {
EntityManager entityManager = session.unwrap(EntityManager.class);
TypedQuery<CEntity> query = entityManager.createQuery("select c from CEntity as c where c.id = :cid ", CEntity.class);
query.setParameter("cid", 1);
CEntity cEntity = query.getSingleResult();
assertThat(cEntity.getA(), isNotInitialized());
assertThat(cEntity.getB(), isNotInitialized());
assertThat(cEntity.getC(), isNotInitialized());
assertThat(cEntity.getDList(), isNotInitialized());
assertThat(statementInspector.getSqlQueries(), hasSize(1));
});
}
use of org.hibernate.testing.jdbc.SQLStatementInspector in project hibernate-orm by hibernate.
the class LoadAndFetchGraphTest method testQueryByIdWithFetchGraph.
@Test
void testQueryByIdWithFetchGraph(SessionFactoryScope scope) {
SQLStatementInspector statementInspector = (SQLStatementInspector) scope.getStatementInspector();
statementInspector.clear();
scope.inTransaction(session -> {
EntityManager entityManager = session.unwrap(EntityManager.class);
EntityGraph<CEntity> entityGraph = entityManager.createEntityGraph(CEntity.class);
entityGraph.addAttributeNodes("a", "b");
entityGraph.addSubgraph("dList").addAttributeNodes("e");
TypedQuery<CEntity> query = entityManager.createQuery("select c from CEntity as c where c.id = :cid ", CEntity.class);
query.setHint(GraphSemantic.FETCH.getJpaHintName(), entityGraph);
query.setParameter("cid", 1);
CEntity cEntity = query.getSingleResult();
assertThat(cEntity.getA(), isInitialized());
assertThat(cEntity.getB(), isInitialized());
assertThat(cEntity.getC(), isNotInitialized());
assertThat(cEntity.getDList(), isInitialized());
cEntity.getDList().forEach(dEntity -> assertThat(dEntity.getE(), isInitialized()));
assertThat(statementInspector.getSqlQueries(), hasSize(1));
});
}
Aggregations