| An inner join, next to left join, does not produce a nested join. It will end to an not intuitive result :
Root<EntityA> root = query.from(EntityA.class);
Join<EntityA, EntityB> aJoinB_LEFT = root.join("bEntities",LEFT);
Join<EntityB, EntityC> bJoinC_INNER = aJoinB_LEFT.join("cEntities",INNER);
bJoinC_INNER.on(
cb.equal(
bJoinC_INNER.get("name"),
"C1"));
It produces :
select
entitya0_.name as col_0_0_,
bentities1_.name as col_1_0_,
centities2_.name as col_2_0_
from
EntityA entitya0_
left outer join
EntityB bentities1_
on entitya0_.id=bentities1_.a_id
inner join
EntityC centities2_
on bentities1_.id=centities2_.b_id
and (
centities2_.name=?
)
and abort the "optionnal effect" of the left join. It returns only entries responding to the left + the inner predicates, and excludes entities not responding to the left join at all (the purpose of left join). A nested join would produce a more intuitive result :
select
entitya0_.name as col_0_0_,
bentities1_.name as col_1_0_,
centities2_.name as col_2_0_
from
EntityA entitya0_
left outer join
EntityB bentities1_
inner join
EntityC centities2_
on bentities1_.id=centities2_.b_id
and (
centities2_.name=?
)
on entitya0_.id=bentities1_.a_id
I understand that "intuitive" is subjective, and that i probably don't know the way to produce a nested join. I joined a some code to illustrate |