use of jakarta.persistence.criteria.ListJoin in project hibernate-orm by hibernate.
the class AbstractQueryCacheResultTransformerTest method testListElementsProjectionList.
@Test
public void testListElementsProjectionList(SessionFactoryScope scope) throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
@Override
protected ResultTransformer getResultTransformer() {
return null;
}
@Override
protected JpaCriteriaQuery getCriteria(Session s) {
CriteriaBuilder builder = s.getCriteriaBuilder();
JpaCriteriaQuery criteria = (JpaCriteriaQuery) builder.createQuery();
Root<Enrolment> root = criteria.from(Student.class);
final ListJoin<Object, Object> secretCodes = root.joinList("secretCodes");
criteria.select(secretCodes);
return criteria;
}
};
HqlExecutor hqlExecutor = new HqlExecutor() {
@Override
public Query getQuery(Session s) {
return s.createQuery("select elements(s.secretCodes) from Student s");
}
};
ResultChecker checker = results -> {
List resultList = (List) results;
assertEquals(3, resultList.size());
assertTrue(resultList.contains(yogiExpected.getSecretCodes().get(0)));
assertTrue(resultList.contains(shermanExpected.getSecretCodes().get(0)));
assertTrue(resultList.contains(shermanExpected.getSecretCodes().get(1)));
};
runTest(hqlExecutor, criteriaExecutor, checker, false, scope);
}
use of jakarta.persistence.criteria.ListJoin in project eclipselink by eclipse-ee4j.
the class CriteriaBuilderImpl method treat.
@Override
public <X, T, E extends T> ListJoin<X, E> treat(ListJoin<X, T> join, Class<E> type) {
ListJoinImpl parentJoin = (ListJoinImpl) join;
ListJoin joinImpl = null;
if (join instanceof BasicListJoinImpl) {
joinImpl = new BasicListJoinImpl<X, E>(parentJoin, this.metamodel, type, parentJoin.currentNode.treat(type), parentJoin.getModel(), parentJoin.getJoinType());
} else {
joinImpl = new ListJoinImpl<X, E>((Path) join, this.metamodel.managedType(type), this.metamodel, type, parentJoin.currentNode.treat(type), parentJoin.getModel(), parentJoin.getJoinType());
}
parentJoin.joins.add(joinImpl);
((FromImpl) joinImpl).isJoin = parentJoin.isJoin;
parentJoin.isJoin = false;
return joinImpl;
}
use of jakarta.persistence.criteria.ListJoin in project hibernate-orm by hibernate.
the class HHH14916Test method testJoinOnFetchNoExceptionThrow.
@Test
public void testJoinOnFetchNoExceptionThrow(EntityManagerFactoryScope scope) {
scope.inTransaction(entityManager -> {
final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
final CriteriaQuery<Author> query = builder.createQuery(Author.class);
final Root<Author> root = query.from(Author.class);
final ListJoin<Author, Book> authorBookJoin = (ListJoin) root.fetch("books", JoinType.LEFT);
final ListJoin<Book, Chapter> bookChapterJoin = authorBookJoin.joinList("chapters", JoinType.LEFT);
final Predicate finalPredicate = builder.equal(bookChapterJoin.get("name"), "Overview of HTTP");
query.where(finalPredicate);
Author author = entityManager.createQuery(query).getSingleResult();
assertEquals("David Gourley", author.name);
assertEquals("HTTP Definitive guide", author.books.get(0).name);
assertEquals("Overview of HTTP", author.books.get(0).chapters.get(0).name);
});
}
Aggregations