Hi, 
I would like to define following query as a Criteria: 
Code:
 
from EscalationStateVO where validTo in (select max(state.validTo) from EscalationStateVO state group by state.escalation.id) 
 The problem is, that the subquery returns 2 result rows and it seems to be impossible to pick 
validTo only. Here is my code: 
Code:
 
DetachedCriteria dc = DetachedCriteria.forClass(EscalationStateVO.class); 
ProjectionList projList = Projections.projectionList(); 
projList.add(Projections.max("validTo")); 
projList.add(Projections.groupProperty("escalation.id")); 
dc.setProjection(projList); 
Criteria crit = session.createCriteria(EscalationStateVO.class); 
crit.add(Property.forName("validTo").in(dc)); 
List l = crit.list(); 
 
This does not function because the generated SQL of the subselect contains 
escalation.id also (grouping is needed there). 
Do you have any clues on that? 
Thanks, 
Gabor