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.  [ 5 posts ] 
Author Message
 Post subject: Count no. of objects using CriteriaAPI
PostPosted: Tue Aug 29, 2006 10:58 am 
Beginner
Beginner

Joined: Sun Jun 19, 2005 2:21 pm
Posts: 21
Hello,

Does anyone know how to make a generic routine which counts the number of objects from a table using CriteriaAPI?

I need something looking like this:

public int GetObjectsCount (Type obj)
{
....
}

If it is not possible to do this using CriteriaAPI, does anyone know a workaround using HQL?

Regards,
Robert


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 03, 2006 12:39 am 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
in HQL

Code:

StringBuilder query = new StringBuilder();
query.Append("select count(*) from Email as e where        e.Text='").Append(text).Append("'");           
query.Append(" group by e.Text");           
IQuery q = Session.CreateQuery(query.ToString());           
int number = q.List().Count;           
return number;


just don't forget the aggregate (group by) expression.

Hope this helps

_________________
If this helped...please remember to rate it!


Top
 Profile  
 
 Post subject: Count no. of objects using CriteriaAPI
PostPosted: Sun Sep 03, 2006 1:50 pm 
Newbie

Joined: Thu Aug 31, 2006 2:54 pm
Posts: 2
What you want is projection as it is implemented in hibernate. This is not yet implemented in nhibernate, but i've uploaded a patch to nh-617 to make this possible. So, if you really want it, download the nhibernate sources, and apply the patch.


Top
 Profile  
 
 Post subject: Re: Count no. of objects using CriteriaAPI
PostPosted: Sun Sep 03, 2006 10:46 pm 
Regular
Regular

Joined: Tue Feb 07, 2006 4:27 pm
Posts: 69
preuse wrote:
What you want is projection as it is implemented in hibernate. This is not yet implemented in nhibernate, but i've uploaded a patch to nh-617 to make this possible. So, if you really want it, download the nhibernate sources, and apply the patch.



Do you know what the timelines are for having Projections added to the main build/release cycle?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 04, 2006 1:24 pm 
Newbie

Joined: Thu Aug 31, 2006 2:54 pm
Posts: 2
Well,

Sergey applied the patch. You can either dowload the sources and compile them, or wait until the 1.2 beta 1 is released.
I have no idea for the beta 1 timeline, soon I hope.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.