jpa - How do I do a "deep" fetch join in JPQL? -


i don't think ever understand fetch joins.

i have query i'm attempting eagerly "inflate" references down 2 levels.

that is, a has optional collection of bs, , each b has either 0 or 1 c. size of b collection known small (10-20 tops). i'd prefetch graph.

a's b relationship marked fetchtype.lazy , optional. b's relationship c optional , fetchtype.lazy.

i hoping do:

select    a   left join fetch a.bs // look, no alias; jpql forbids   left join a.bs b // "repeated" join necessary since can't alias fetch joins   left join fetch b.c // doesn't seem  a.id = :id 

when run this, see as b collection indeed fetched (i see left join in sql referencing table b mapped).

however, see no such evidence c's table fetched.

how can prefetch cs , bs , cs "reachable" given a? can't see way this.

the jpa spec not allow aliasing fetch join, jpa providers do.

eclipselink of 2.4. eclipselink allow nested join fetch using dot notation (i.e. "join fetch a.bs.c"), , supports query hint "eclipselink.join-fetch" allows nested joins (you can specify multiple hints of same hint name).

in general need careful when using alias on fetch join, can affect data returned.

see, http://java-persistence-performance.blogspot.com/2012/04/objects-vs-data-and-filtering-join.html


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -