To convert the JPQL "join fetch" with a "where" clause into a JPA 2 CriteriaQuery, you can follow the below steps:
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Order> query = cb.createQuery(Order.class);
Root<Order> orderRoot = query.from(Order.class);
orderRoot.fetch("customer", JoinType.INNER);
Predicate predicate = cb.equal(orderRoot.get("status"), "PROCESSING");
query.where(predicate);
List<Order> orders = entityManager.createQuery(query).getResultList();
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-17 15:20:44 +0000
Seen: 8 times
Last updated: Jun 17 '23