I don't think I will ever fully understand fetch joins.
I have a query where I'm attempting to eagerly "inflate" references down two levels.
That is, my A
has an optional Collection
of B
s, and each B
has either 0 or 1 C
. The size of the B
collection is known to be small (10-20 tops). I'd like to prefetch this graph.
A
's B
relationship is marked as FetchType.LAZY
and is optional. B
's relationship to C
is also optional and FetchType.LAZY
.
I was hoping I could do:
SELECT a
FROM A a
LEFT JOIN FETCH a.bs // look, no alias; JPQL forbids it
LEFT JOIN a.bs b // "repeated" join necessary since you can't alias fetch joins
LEFT JOIN FETCH b.c // this doesn't seem to do anything
WHERE a.id = :id
When I run this, I see that A
s B
collection is indeed fetched (I see a LEFT JOIN
in the SQL referencing the table to which B
is mapped).
However, I see no such evidence that C
's table is fetched.
How can I prefetch all C
s and all B
s and all C
s that are "reachable" from a given A
? I can't see any way to do this.
eclipselink.join-fetch
andeclipselink.batch
hints... – Antineclipselink.join-fetch
, it looks like I'm permitted to set only one attribute. Is that correct? For example, if I blow myjoin-fetch
capital ona.bs.c
, then if I also wanted to join fetch—say—a.bs.d
I'd be out of luck. Right? – Penceleclipselink.join-fetch
hints do work. We use it heavily at work and generated SQL statements are correct. – Antin