JPQL joins and benefit/drawbacks of fetch joins

JPQL can handle LEFT OUTER JOIN (may be abbreviated to LEFT JOIN) and INNER JOIN (may be abbreviated to JOIN or to IN() <- don't use AS for the alias of "right hand side" here in combination with hibernate). The following document describes the different types of joins: visual explanation of sql joins.

The definition can be used analogously for JPQL joins. Fetch joins enable to retrieve lazy associations in an outer join within the “host query”. So there is only one query instead of 2 for subselect fetching or even n+1 for select fetching. Unfortunately these fetch joins cannot be used in combination with an alias and they cannot be referenced in the WHERE, GROUP BY, HAVING or ORDER BY clause.

Leave a Reply

Your email address will not be published. Required fields are marked *