-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Subselect with group by in a Criteria
PostPosted: Wed Jan 24, 2007 4:10 pm 
Newbie

Joined: Wed Jan 17, 2007 5:55 am
Posts: 2
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.