-->
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: Criteria: How to get paged results & total efficiently?
PostPosted: Wed Oct 01, 2008 5:42 am 
Newbie

Joined: Wed Jun 06, 2007 7:11 am
Posts: 2
Using criteria, how can one efficiently get a page of results and the total number of results.

Environment is Oracle 10g if that makes any difference.

If I understand the docs correctly, the usual way is to execute one query to get the page of results (with maxResults and firstResult set) and then another using a count(*) projection to get the total number of results.

The query I'm working with is very slow so I'm trying to avoid having to execute it twice like this.

Another option would be to obtain a ScrollableResults, extract the data and then call last() and getRowNumber() for the total. However, from the docs it looks like this exposes only raw data rather than domain objects which would be a pain.

I'm thinking either I've misunderstood something or there is an obvious solution I'm missing. Appreciate any tips.

Cheers,
Derek


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2008 10:17 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
No, you haven't misunderstood anything.
The very simple feature of giving you the total count along with the page results (which appear to be calculated internally anyways), Hibernate doesn't expose it to you, and you are forced to issue 2 queries.

I can't understand why they do that, it's inexplicable.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2008 11:41 am 
Newbie

Joined: Wed Jun 06, 2007 7:11 am
Posts: 2
Thanks for the reply. It certainly is inexplicable. I'm incredulous.

There needs to be something like this.

.setProjections(
Projection.type(MyClass.class), Projection.rowCount()
)

* Projection.type being my request for enhancement.

Will have to look to HQL I suppose.


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.