-->
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.  [ 2 posts ] 
Author Message
 Post subject: how to do the group by and having in criteria.
PostPosted: Tue Apr 06, 2010 7:09 am 
Newbie

Joined: Tue Apr 06, 2010 6:44 am
Posts: 2
hi,

i do not know how to do the group by and having by using the criteria.

i have to solve the following query using criteria.

"select EmployeeNo from employee group by projectid having projectid=1"

please give the answer.

Thanks.


Top
 Profile  
 
 Post subject: Re: how to do the group by and having in criteria.
PostPosted: Tue Apr 06, 2010 8:38 am 
Beginner
Beginner

Joined: Fri Aug 24, 2007 9:47 am
Posts: 21
You need to use projections to do this because there is no explicit "group by" necessary in a criteria query. Certain projection types are defined to be grouping projections, which also appear in the SQL group by clause.

An alias can be assigned to a projection so that the projected value can be referred to in restrictions or orderings.

Here are two different ways to do this:

List results = session.createCriteria(Cat.class)
.setProjection( Projections.groupProperty("color").as("colr") )
.addOrder( Order.asc("colr") )
.list();

_________________
recherche-programmeur.fr


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

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.