-->
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: Aggregate function in where clause (Criteria API)
PostPosted: Mon Sep 04, 2006 5:48 am 
Newbie

Joined: Mon Sep 04, 2006 5:27 am
Posts: 1
Location: Lahore pakistan
I am using Criteria API. I want to use the Aggregate Functions like
Avg(),count() etc in the where clause i know its available through Projections but projections used as the slect part of the query i want to use these functions in where clause like
criteria.add(Restriction.eq(Projections.count("emp"),5));

Is there any way to do that.

if the problem is not clear lets say i have two tables Employee and Address and the relation between is one to many Employee have multiple Addresses so i want to retrieve the employee who have 5 or more Addresses.

Code is like that.

Code:
Criteria criteria = session.createCriteria(Employee.class,"emp");
      criteria.setFetchMode("addresses",FetchMode.EAGER);
ProjectionList projList = Projections.projectionList();
projList.add(Projections.count("emp.addresses"),"NoOfOpp");
criteria.setProjection(projList);
criteria.add((Restrictions.ge("NoOfOpp",6)));
List list=criteria.list();



When i execute this it gives me NoOfOpp invalid identifier is any other way round to accomplish the task.

_________________
Regards,
Muhammad Shouab


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.