-->
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: Counting records in a database when criteria querying
PostPosted: Tue Jul 18, 2006 2:28 pm 
Regular
Regular

Joined: Sun Feb 12, 2006 10:18 pm
Posts: 60
Location: Rosario, Argentina
Is there a way to find out the number of records that match a specified criteria without fetching the data? I need this to implement paging in my web app: the user can search filtering by some properties, but could also just hit the "search" button without entering any filters, which would end retrieving every record in a large table.
Please keep in mind that I'm using Citeria querying, not HQL.

Thanks for trying to answer me!
Alejandro


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 6:18 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Set the criteria's projection to Projections.rowCount().

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 9:09 am 
Regular
Regular

Joined: Sun Feb 12, 2006 10:18 pm
Posts: 60
Location: Rosario, Argentina
Your answer is a good guidance, but still I can't solve the problem. I found in JIRA an issue that is supposed to solve this problem:

http://jira.nhibernate.org/browse/NH-617?page=all

I downloaded the code and put it into the NHibernate project. It didn't compile, but all errors where in a single cs file (AbstractEmptynessExpression.cs). I tried to fix them, I guess the problem was with the NH version because some of the errors where regarding namespaces and differences in names. I couldn't fix them all, so I just erased the file, and voilĂ , the project compiled. Yet, I can't add the projection to the criteria nor I can find an exaple of how to use this...

Help!!!

Also: I'm using NH 1.0.2.0, is this the latest stable version?

Alejandro.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 10:51 am 
Beginner
Beginner

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

By the way... for which version of NHibernate is the projections code from JIRA and how do I integrate it into NHibernate so that I can access something like this:

Code:
IList results = session.createCriteria(typeof(AnObject)) .setProjection(Projections.projectionList()
.add(Projections.rowCount())).list();


Regards,
Robert


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.