title: JPA Criteria select all instances with max values in their groups
body: <p>Is there a way to write with JPA 2 <code>CriteriaBuilder</code> the equivalent of the following query?</p>
  
  <pre class="lang-sql prettyprint-override"><code>select * from season s1
  where end = (
      select max(end)
      from season s2
      where s1.contest_id=s2.contest_id
  );
  </code></pre>
  
  <p>In JPQL this query is:</p>
  
  <pre><code>Select s1 from Season s1 
  where s1.end = (
      select max(s2.end)
      from Season s2
      where s1.contest=s2.contest
  )
  </code></pre>