olivmir
olivmir

Reputation: 722

JPA: No join method for Fetch interface

Via JPA Criteria Api

What is the reason? Why an attribute of a fetched entity in turn can not be joined (without fetch)?

For example:

root.join(entity1_attribute, JoinType.INNER)
    .join(entity2_attribute, JoinType.INNER)
    .fetch(entity3_attribute, JoinType.INNER) 

is possible.

But

root.join(entity1_attribute, JoinType.INNER)
    .fetch(entity2_attribute, JoinType.INNER)
    .join(entity3_attribute, JoinType.INNER) //<--

is not possible.

Upvotes: 0

Views: 48

Answers (1)

Christian Beikov
Christian Beikov

Reputation: 16400

It is this way for the same reason that the JPQL BNF does not allow aliasing fetch joins, because nested fetches do not have to be supported according to the JPA specification. You can ask on the JPA mailing list or create an issue to request making Fetch extend Join or something like that if you want.

Upvotes: 1

Related Questions