title: NamedQuery join and filter collection
body: <p>I've tried to do this query but it still selects every child even though I just want the ones with the specific name. How would I achieve that?</p>
  
  <pre><code>@NamedQuery(name="Parent.getChildrenWithName",
                  query="SELECT p FROM Parent p "
                          + "join p.children c "
                          + "where c.name = :childName")
  public class Parent
  {
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "parentId")
      private List&lt;Child&gt; children;
  }
  
  public class Child
  {
      @Column(name = "ChildName")
      private String childName;
  
      private int parentId;
  }
  </code></pre>
  
  <p>Just read this on <a href="http://docs.oracle.com/javaee/6/tutorial/doc/bnbtl.html#bnbtr" rel="nofollow">http://docs.oracle.com/javaee/6/tutorial/doc/bnbtl.html#bnbtr</a>:</p>
  
  <p><em>Expressions cannot navigate beyond (or further qualify) relationship fields that are collections. In the syntax of an expression, a collection-valued field is a terminal symbol. Because the teams field is a collection, the WHERE clause cannot specify p.teams.city (an illegal expression).</em></p>
  
  <p>This is my code that fetches the result:</p>
  
  <pre><code>TypedQuery&lt;Parent&gt; query = em.createNamedQuery("Parent.getChildrenWithName", Parent.class);
  query.setParameter("childName", "Daniel");
  Parent parent = query.getSingleResult();
  </code></pre>
  
  <p>But the question remains :)</p>