I don't understand your first question fully, but if your pagination problem is the same as mine, you need to get the count of the full result, and then just retrieve the selected page. I found the answer to this problem searching this forum:
First, to count:
Code:
criteria.setProjection(Projections.rowCount());
Integer count = (Integer) criteria.uniqueResult();
Then, just afterwards to get the criteria back into "normal" mode:
Code:
criteria.setProjection(null);
criteria.setResultTransformer(Criteria.ROOT_ENTITY);
I was using a ScrollingResult to get the count, and on MySQL this was taking close to a second. With a projection query it's taking 50ms.