title: Hibernate Criteria API - how to order by collection size?
body: <p>Assuming I have classes User and UserGroup. There is an optional 1-many group to user association and the association is mapped from both sides (the UserGroup side via a property called "members", which is a HashSet, the User side via property "group").</p>
  
  <p>Using the Criteria API, how can I query for all groups, sorted by count of group members?</p>
  
  <p>(Edit) I should have pointed out when I asked this that pagination was being performed in the SQL, so the ordering should also be performed in the SQL if possible.</p>