title: How do I do a "deep" fetch join in JPQL?
body: <p>I don't think I will ever fully understand fetch joins.</p>
  
  <p>I have a query where I'm attempting to eagerly "inflate" references down two levels.</p>
  
  <p>That is, my <code>A</code> has an optional <code>Collection</code> of <code>B</code>s, and each <code>B</code> has either 0 or 1 <code>C</code>.  The size of the <code>B</code> collection is known to be small (10-20 tops).  I'd like to prefetch this graph.</p>
  
  <p><code>A</code>'s <code>B</code> relationship is marked as <code>FetchType.LAZY</code> and is optional.  <code>B</code>'s relationship to <code>C</code> is also optional and <code>FetchType.LAZY</code>.</p>
  
  <p>I was hoping I could do:</p>
  
  <pre><code>SELECT a 
    FROM A a
    LEFT JOIN FETCH a.bs // look, no alias; JPQL forbids it
    LEFT JOIN a.bs b // "repeated" join necessary since you can't alias fetch joins
    LEFT JOIN FETCH b.c // this doesn't seem to do anything
   WHERE a.id = :id
  </code></pre>
  
  <p>When I run this, I see that <code>A</code>s <code>B</code> collection is indeed fetched (I see a <code>LEFT JOIN</code> in the SQL referencing the table to which <code>B</code> is mapped).</p>
  
  <p>However, I see no such evidence that <code>C</code>'s table is fetched.</p>
  
  <p>How can I prefetch all <code>C</code>s and all <code>B</code>s and all <code>C</code>s that are "reachable" from a given <code>A</code>?  I can't see any way to do this.</p>