Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Are multiple FETCH JOINs allowed by JPA specification?


 I want to optimize my query so that I define multiple fetch joins for
my relationships that have been defined FetchType=LAZE.

Quickly researched, and some links such as this suggest that I can
define only one JOIN FETCH:

"Unfortunately JPA 1 and 2 do not support join fetches over multiple tables.
The spec says: "It is not permitted to specify an identification
variable for the objects referenced by the right side of the FETCH
JOIN clause, and hence references to the implicitly fetched entities
or elements cannot appear elsewhere in the query."
I think this is the most annoying part of the specification,"...

But, when I try this in practice with EclipseLink, multiple join
fetches seem to work fine:

    @NamedQuery(name = "Employer.findUsingEagerFetch", query = "select
o from Employer o JOIN FETCH o.address JOIN FETCH o.persons..."),

This loads the employer and related address and persons with a single
query. The created SQL looks perfectly sane to me.

QUESTION: Is this indeed violating the JPA specification and am I
creating unportable code doing so? The specification quote
unfortunately is a bit hard to understand fully.

Back to the top