-->
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.  [ 3 posts ] 
Author Message
 Post subject: Pagination: How to get page plus total results in one query
PostPosted: Thu Apr 17, 2008 9:13 pm 
Newbie

Joined: Sun Sep 30, 2007 6:10 am
Posts: 2
Hi,

I have pagination working, but am doing so with two queries; one to get the results page and a second one to get the total count.

I'd like to do this in a single query: Is it possible to build a criteria, so my results set includes columns for each of the properties on my bean, plus an additional column which has the row count (downside: this is duplicated for each row in the page).

I figured I could build a projection like this to return all the beans properties plus the row count.

private Projection getProjectionsForBeanAndRowCount() {
ClassMetadata classMetadata = session().getSessionFactory().getClassMetadata(modelClass);

ProjectionList projectionList = Projections.projectionList();
projectionList.add(Projections.rowCount());
String[] propertyNames = classMetadata.getPropertyNames();
for (String propertyName : propertyNames) {
projectionList.add(Projections.property(propertyName));
}
return projectionList;
}

..and then write a ResultsTransformer to process these results, instantiating a class like:-

public class PageResult {
Object bean;
int rowCount;
}

..but it seems that by the time ResultsTransformer is called, you already have the bean instantiated.

Is there a way I can jump in at a slightly lower level, the level where the results bean's are built?

Any info much appreciated.

All the best, Jon


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 23, 2008 5:23 am 
Regular
Regular

Joined: Mon Mar 06, 2006 6:18 am
Posts: 95
Location: Bern, Switzerland
hello!

have you found a solution to your problem??

regards angela


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 23, 2008 10:31 am 
Newbie

Joined: Wed Apr 12, 2006 2:13 pm
Posts: 3
I had just posted about the same thing earlier here

http://forum.hibernate.org/viewtopic.ph ... 11#2386011

User Christian Maslen was kind enough to point me to the following page that gave me the way to accomplish this

http://www.ayende.com/Blog/archive/2007 ... y-way.aspx


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