title: Correct way to query an entity with nested collections?
body: <p>It looks like basic queries don't work when collection elements have collections of their own.</p>
  
  <p>Imagine a data model for a bank with customers, which have portfolios, which have investments. What is the correct way to get customers?</p>
  
  <p>I tried this:</p>
  
  <pre><code>@Query("SELECT DISTINCT c FROM Customer c LEFT JOIN FETCH c.portfolios")
  </code></pre>
  
  <p>But it fails with "Failed to lazily initialize a collection of role".</p>
  
  <p>Investments is defined as:</p>
  
  <pre><code>@ManyToMany(cascade = CascadeType.ALL)
  </code></pre>
  
  <p>The query will work, if I change the fecthType:</p>
  
  <pre><code>@ManyToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER)
  </code></pre>
  
  <p>But is there a way to make it work without changing the fetchtype? </p>
  
  <p>EDIT:</p>
  
  <p>I should mention that I used Spring's JpaRepository to define the above query. All entities have their respective repositories, but it looks like fetching Customers does not touch any methods in Portfolios repository (which would LEFT JOIN the Investments) and so the investments are never fetched.</p>
  
  <p>Also, I can fetch a Portfolio with a similar query and it works fine as Investment does not have any collections. But fetching the chain customer -> portfolios -> investments fails.</p>