Is there any way to write a greatest-n-per-group query in HQL (or potentially with Hibernate Criteria) in a single query?
I\'m struggling with a problem that\'s similar
For that, you need a SQL window function. There is no way to do it in Hibernate/HQL, HQL doesn't support window functions.
greatest-n-per-group tag has the correct answers. For instance, this approach is pretty readable, though not always optimal.
greatest-n-per-group