2.10.2.3.7. JPQL Outer Joins
LEFT JOIN and LEFT OUTER JOIN are synonymous.
They enable the retrieval of a set of entities where matching values in the join condition may be absent.
The syntax for a left outer join is:
-
LEFT [OUTER] JOIN join_association_path_expression [AS] identification_variable
For example:
SELECT pub FROM Publisher pub LEFT JOIN pub.magazines mag WHERE pub.revenue 1000000
The keyword OUTER may optionally be used:
SELECT pub FROM Publisher pub LEFT OUTER JOIN pub.magazines mags WHERE pub.revenue 1000000
An important use case for LEFT JOIN is in enabling the prefetching of related data items as a side effect of a query.
This is accomplished by specifying the LEFT JOIN as a FETCH JOIN.