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
|