-->
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: Getting better a paging query solution
PostPosted: Wed Jun 02, 2004 1:27 pm 
Newbie

Joined: Wed Jun 02, 2004 12:50 pm
Posts: 3
Location: Central America
I'm using Hibernate 2.1.3.

I'm implementing a paging solution for queries.

I coded it this way with some help from an Eclipse plugin named Hibernate Synchronizer:

public function getNamedQueryPageable(String name, Map params, session s,int maxresults,int firstresult)

Query q = s.getNamedQuery(name);
if (null != params) {
for (Iterator i=params.entrySet().iterator(); i.hasNext(); ) {
Map.Entry entry = (Map.Entry) i.next();
setParameterValue(q, (String) entry.getKey(), entry.getValue());
}
}

q.setFirstResult(firstresult);
q.setMaxResults(maxresults);
return q.list();
}

My problem occurs when i tried to get the number of total rows that results from the query, not only the number of rows that I retrieved.

I could make a siple query: "select count(*)..." as decribed in documentation, but I want to know if there is a simpler way.

If there isn't, what do you think about a feature request for this ability in the class Query.

_________________
Thank you!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 02, 2004 1:43 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
No, select count() is the way to do this.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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.