Hi
I have written an application with search screens where I use Hibernate's 2.1 Criteria API to dynamically generate select queries. I use setFirstResult() and setMaxResult to implement paging of result set, because there can be a lot of records in database.
Now I need to get total number of records that satisfy given criteria. So I can display something like "x-y from total z records". Which would be the best way to get total number of records ? I have some ideas, for example:
1) If it's possible to get SQL statement generated by Hibernate (?) I could modify by replacing fields with "count (*)"
2) It's also possible to read all records from db and display just a subset, but it would have very bad performance.
Any ideas ?
|