Hibernate version: 2.1.6
I need to display a table in a Web UI that supports
-sorting
-filtering on one or more columns
-pagination
The table is based on a single domain Entity class. To accomplish this I'm building the query dynamically using a generic routine that uses the hibernate Criteria class. The filter, sort and paging info is passed to the routine the builds the 'Criteria' using the Expression and Order helper classes. All this works well.
However I also have the requirement that the table in the UI display the total number of pages. The Pagination solution in the Hibernate blogs (
http://blog.hibernate.org/cgi-bin/blosx ... ation.html) does not address this however its pretty simple to do when working with the Query class. One can simply call
Code:
query.scroll()
to get a
Code:
ScrollableResults results
instance. Working with the 'results' instance one can set the start position and results size based on the table page number and page size and finally determine the number of pages navigating to the last record
Code:
results.last()
and then calling
Code:
results.getRowNumber().
Unfortunately when working with the Criteria API, I cannot get a handle to the ScrollableResults and therefore can't determine the total number of records. Am I missing a way to determine the total number of records using the scrollable resultset feature when working with the Criteria API?
I was looking for an API on the Criteria class that looks like
ScrollableResults scroll() or
Query query()
Thanks,
Sanjiv