title: Hibernate Criteria with projection: how to group by / get the main entity?
body: <p>I have an <code>Entity</code> class mapped with a 1-N association with <code>AnotherEntity</code> class, and I want to perform a query to get entities with some restrictions alongside the maximum <code>n</code> property of the <code>AnotherEntity</code> objects associated with them.</p>
  
  <p>Currently, I have the following code:</p>
  
  <pre><code>Criteria c = session.createCriteria(Entity.class, "e");
  c.createAlias("e.anotherEntitySet", "otherEntities");
  c.add(Restrictions.eq("someEntityProperty", someEntityPropertyValue));
  ProjectionList projectionList = Projections.projectionList();
  projectionList.add(Projections.max("otherEntities.n"));
  projectionList.add(Projections.groupProperty("pk"));
  c.setProjection(projectionList);
  List resultList = c.list();
  </code></pre>
  
  <p>The problem is that <code>resultList</code> is filled by <code>Object[]</code> elements containing the maximum <code>n</code> and the <code>pk</code> property of entities. While I want the maximum <code>n</code>, I don't want just the <code>pk</code> property: I want the whole <code>Entity</code> objects.</p>
  
  <p>How can I obtain them, and still performing a single query in the process?</p>