How to make a CriteriaBuilder join with a custom “on” condition?

It is possible starting from the version 2.1 of JPA using the on method Join<Z, X> on(Predicate... restrictions);

Here is how:

Root<Order> order = cq.from(Order.class);
Join<Order, Item> item = order.join(Order_.itemList, JoinType.LEFT);
item.on(cb.equal(item.get(Item_.type), 1));

Leave a Comment