Dencel wrote:
beniji wrote:
Guys
You dont need to do the "double criteria" hacking.
After you get the row count, just do this (on the same Criteria):
Code:
crit.setResultTransformer( Criteria.ROOT_ENTITY );
crit.setProjection( null );
.. and hey presto
you can re-use the same criteria object.
HTH,
Ben
Actually, it's the other way arround:
Code:
crit.setProjection( null );
crit.setResultTransformer( Criteria.ROOT_ENTITY );
setProjection sets the ResultTransformer to PROJECTION.
This approach doesn't work if the original criteria contained a projection, since you are overwriting it with null. I think you need to save the original projection that the criteria might contain AND the original ResultTransformer and restore them afterwards (as opposed to just setting it to null).
I describe my approach in the following thread:
http://forum.hibernate.org/viewtopic.php?t=974802 (Pagination with Projection.rowCount() in a single call?).
(The fourth post from Octuber 31)