title: Hibernate HQL: using JOIN to eagerly load child entities?
body: <p>I found this HQL query that I am trying to make sense of. The comment says the <code>LEFT JOIN</code> causes Hibernate to eagerly load the associated entities in the child table, and the <code>DISTINCT</code> modifier is needed to filter out duplicate parent entities in the result set. Do these comments make sense? I have not seen a join used this way before.</p>
  
  <pre><code>SELECT DISTINCT p FROM Parent AS p
  LEFT JOIN p.children AS c
  WHERE p.state = 1
  ORDER BY p.modified
  </code></pre>
  
  <p>Note <code>c</code> is not used in the <code>WHERE</code> or <code>ORDER BY</code> clauses.</p>
  
  <p>It seems it would be safe to replace this query with the simpler:</p>
  
  <pre><code>SELECT p FROM Parent AS p
  WHERE p.state = 1
  ORDER BY p.modified
  </code></pre>
  
  <p>But I am not sure if there is a <em>good reason</em> the original query was written as is.</p>