May be questions like this where already posted, but I couldn't find them searching the forum, so please pardon the re-post.
I'm trying to give to my development group a support class to simply paginate over a Criteria or Query results.
My
Paginator class must extract from the Query or Criteria the SQL ready to be executed on the DB and use it as the FROM clause of a SELECT COUNT(*) to compute the results count.
So, for a given Criteria or Query with any parameter or criterion alredy setted and established, I want to execute:
Code:
StringBuffer buffer = new StringBuffer("select count(*) from (");
// the original Criteria/Query with fields/parameters replaced with actual values
buffer.append(")");
Iterator iterator = session.iterate(buffer.toString());
count = ((Integer)iterator.next()).intValue();
Or something which produces the same output... is there a clean solution?
Hibernate version:
we are currently using 2.1.8, but we are ready to migrate to 3 so solutions for both are welcome.