title: JPA query with subselect
body: <p>I would like to express the following query</p>
  
  <pre><code>select * from(
              select pI, max(pAs) as pAs from mytable
              and pAs&gt;=?1 and pAs&lt;=?2
              and pI like 'DE%%'
              and pE like ?6
              group by pI
              ) as x
              inner join mytable as a
              on a.pI=x.pI
              and a.pAs=x.pAs
  </code></pre>
  
  <p>using the criteriabuilder from hibernate. I did not succeed and thus far use a nativeQuery instead.</p>
  
  <p>However, the crux of the matter (which i could not resolve) appears to be that I need two properties returned in the subselect. All the examples i found only return one property.</p>
  
  <p>Is this really a limitation of jpa/hibernate or is there a way to do what i want?
  Any help/pointers are appreciated.</p>