title: Select subset of the list contained in an entity
body: <p>Say I want to get all rows of the <code>MyEntity</code> that have an id lower than 10. This entity contains a list of <code>Another</code> entity. I would like this list to be fetched only by a subset of the <code>listAnother</code>. This subset containing only <code>Another</code> where the <code>user</code> contained in it is a specific one.</p>
  
  <p>Basically in SQL it would be like this :</p>
  
  <pre><code>SELECT * FROM myentity m
  LEFT JOIN another a
  ON m.idTable=a.my_entity
  AND a.user = "test1"
  WHERE m.idTable &lt; 10;
  </code></pre>
  
  <p>I didn't manage however to translate this query to jpql. </p>
  
  <p>My entities being like this :</p>
  
  <pre><code>@Entity
  public class MyEntity implements Serializable {    
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private int idTable;
  
      @OneToMany(mappedBy = "myEntity")
      private List&lt;Another&gt; listAnother;
  
  }
  
  @Entity
  public class Another implements Serializable {    
      @Id
      private int idAnother;
  
      // bi-directional many-to-one association to Thethread
      @ManyToOne(fetch = FetchType.LAZY)
      private MyEntity myEntity;
  
      @ManyToOne(fetch = FetchType.LAZY)
      private User user;
  }
  
  @Entity
  public class User implements Serializable {
  
      @Id
      private String username;
  }
  </code></pre>
  
  <hr>
  
  <p>In jpa I could do this :</p>
  
  <pre><code>SELECT m FROM MyEntity where m.idTable &lt; 10;
  </code></pre>
  
  <p>And then for each entity I get from this list call this:</p>
  
  <pre><code>SELECT a FROM Another Where a.user.username=:'test' AND a.myEntity=:entity;
  </code></pre>
  
  <p>However I would like to do it all at once in one query. Can I do this with criteria ? I didn't take the time to learn it but if it's possible then I will.</p>