title: JPA 2 Criteria Fetch Path Navigation
body: <p>With JPA 2 Criteria Join method I can do the following:</p>
  
  <pre><code>    //Join Example (default inner join)
      int age = 25;
      CriteriaBuilder cb = entityManager.getCriteriaBuilder();
      CriteriaQuery&lt;Team&gt; c = cb.createQuery(Team.class);
      Root&lt;Team&gt; t = c.from(Team.class);
      Join&lt;Team, Player&gt; p = t.join(Team_.players);
      c.select(t).where(cb.equal(p.get(Player_.age), age));
      TypedQuery&lt;Team&gt; q = entityManager.createQuery(c);
      List&lt;Team&gt; result = q.getResultList();
  </code></pre>
  
  <p>How can I do the same with fetch method, I expected that Fetch interface had get method for path navigation but it doesn't:</p>
  
  <pre><code>    //Fetch Join Example
  
      int age = 25;
      CriteriaBuilder cb = entityManager.getCriteriaBuilder();
      CriteriaQuery&lt;Team&gt; cq = cb.createQuery(Team.class);
      Root&lt;Team&gt; t = cq.from(Team.class);
      Fetch&lt;Team,Player&gt; p = t.fetch(Team_.players);
      cq.where(cb.equal(p.get(Player_.age), age)); //This leads to compilation error there is no such method get in interface Fetch
      TypedQuery&lt;Team&gt; q = entityManager.createQuery(cq);
      List&lt;Team&gt; result = q.getResultList();
  </code></pre>
  
  <p>According to Hiberante Documentation fetch returns a Join object which is wrong.
  <a href="http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html/querycriteria.html#querycriteria-from-fetch">http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html/querycriteria.html#querycriteria-from-fetch</a></p>