-->
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.  [ 4 posts ] 
Author Message
 Post subject: Getting result count with Criteria API
PostPosted: Tue Jul 07, 2009 1:16 pm 
Beginner
Beginner

Joined: Mon Jul 07, 2008 8:07 pm
Posts: 42
Is there a way to get a count of the number of results that would be returned by the Criteria API?

Eg:
Code:
session.createCriteria(User.class).add(Restrictions.ge("years", 5).count()


Top
 Profile  
 
 Post subject: Re: Getting result count with Criteria API
PostPosted: Tue Jul 07, 2009 3:38 pm 
Regular
Regular

Joined: Fri Jan 30, 2009 10:10 am
Posts: 74
Location: London
Hi,

Have you looked into Projections?

Perhaps something like:

session.createCriteria(User.class).add(Restrictions.ge("years", 5).setProjection(Projections.rowCount());



--
Stephen Souness



blog: http://elegant-solutions.blogsot.com/


Top
 Profile  
 
 Post subject: Re: Getting result count with Criteria API
PostPosted: Tue Jul 07, 2009 4:02 pm 
Beginner
Beginner

Joined: Mon Jul 07, 2008 8:07 pm
Posts: 42
I think this is exactly what I'm looking for. Thanks!


Top
 Profile  
 
 Post subject: Re: Getting result count with Criteria API
PostPosted: Tue May 25, 2010 5:25 pm 
Newbie

Joined: Tue May 25, 2010 5:16 pm
Posts: 3
And when we have a Join table in select?
How do to get a Projection.rowCount() ??

The Hibernate ignores the join.

tks


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