14.3. Associations and joins
join. For example:
from Cat as cat inner join cat.mate as mate left outer join cat.kittens as kitten
from Cat as cat left join cat.mate.kittens as kittens
from Formula form full join form.parameter param
left outer join
right outer join
full join(not usually useful)
left outer joinand
right outer joinconstructs may be abbreviated.
from Cat as cat join cat.mate as mate left join cat.kittens as kitten
from Cat as cat left join cat.kittens as kitten with kitten.bodyWeight > 10.0
from Cat as cat inner join fetch cat.mate left join fetch cat.kittens
whereclause (or any other clause). The associated objects are also not returned directly in the query results. Instead, they may be accessed via the parent object. The only reason you might need an alias is if you are recursively join fetching a further collection:
from Cat as cat inner join fetch cat.mate left join fetch cat.kittens child left join fetch child.kittens
fetchconstruct cannot be used in queries called using
scroll()can be used).
Fetchshould not be used together with
setFirstResult(), as these operations are based on the result rows which usually contain duplicates for eager collection fetching, hence, the number of rows is not what you would expect.
Fetchshould also not be used together with impromptu
withcondition. It is possible to create a cartesian product by join fetching more than one collection in a query, so take care in this case. Join fetching multiple collection roles can produce unexpected results for bag mappings, so user discretion is advised when formulating queries in this case. Finally, note that
full join fetchand
right join fetchare not meaningful.
fetch all properties.
from Document fetch all properties order by name
from Document doc fetch all properties where lower(doc.name) like '%cats%'