user902383
user902383

Reputation: 8640

How to do JOIN ON query using Criteria API

Since version 2.1 JPA supports join on. I found few examples how to use join on in JPQL but none for Criteria API, and here is my question:

Is JOIN ON is implemented in Criteria APi? And if yes, Can anyone provide example?

Upvotes: 5

Views: 8495

Answers (1)

Neil Stockton
Neil Stockton

Reputation: 11531

Try something like this

CriteriaQuery<Person> crit = cb.createQuery(Person.class);
Root<Person> candidateRoot = crit.from(Person.class);
Join<Person, Address> addrJoin = candidateRoot.join(Person_.address, JoinType.INNER);
addrJoin.on({some predicate});

filling "{some predicate}" with whatever ON clause you want to impose.

Upvotes: 6

Related Questions