Consider the following JPQL query:
SELECT foo FROM Foo foo INNER JOIN FETCH foo.bar bar WHERE bar.baz = :baz I'm trying to translate this into a Criteria query. This is as far as I have gotten:
var cb = em.getCriteriaBuilder(); var query = cb.createQuery(Foo.class); var foo = query.from(Foo.class); var fetch = foo.fetch(Foo_.bar, JoinType.INNER); var join = foo.join(Foo_.bar, JoinType.INNER); query.where(cb.equal(join.get(Bar_.baz), value); The obvious problem here is that I am doing the same join twice, because the Fetch class doesn't seem to have a method to get a Path. Is there any way to avoid having to join twice? Or do I have to stick with good old JPQL with a query as simple as that?