title: JPA Criteria join
body: <p><br/>
  I have two entity classes with many to one relation. I need to select all the parent records that has a child record with a min value smaller than provided.<br/></p>
  
  <p><code>
  @Entity <br/>
  class Parent; { <br/>
  String source; <br/>
  } <br/></p>
  
  <p>@Entity <br/>
  class child { <br/>
  @ManyToOne Parent parent; <br/>
  int value; <br/>
  }
  </code></p>
  
  <p>What I need is to select all the Parent classes where Parent.source = X and min(Child.value> &lt; Y. How to add the join on the parent/child entity and the specific select criteria?</p>
  
  <p><code>
  CriteriaBuilder cb = context.em().getCriteriaBuilder(); <br/>
  CriteriaQuery cq = cb.createQuery(Parent.class); <br/>
  Root r = cq.from(Parent.class); <br/>
  Predicate p = cb.conjunction(); <br/>
  p = cb.and(p, cb.equal(r.get("source"), X)); <br/>
  Expression y = cb.literal(Y); <br/>
  // what to do with y? <br/>
  cq.where(p); <br/>
  TypedQuery tq = context.em().createQuery(cq); <br/>
  tq.setFirstResult(0); <br/>
  tq.setMaxResults(100); <br/>
  return tq.getResultList(); <br/>
  </code></p>