I have a combination of search criteria which implemented by using hibernate criteria. And I added a pagination like this :
criteria.setFirstResult(offset).setMaxResults(pageSize).setFetchSize(pageSize).list();
This is not enough for a pagination , so I have count the total result size .
totalResult = (Integer)criteria.setProjection(Projections.rowCount()).uniqueResult();
The problem is , the first time I submit the search form , I got correct totalResult. When I click next page , and the offset changes , I got a NullPointExcetion at second statement . I don't know why . And through debugging , I can see when this exception occurs , the first statement successfully return the paginated results.
So I want to ask , does the first statement conflict the second ? (because the first statement set the fetchsize to 10 , and I wonder if the count(*) function will work properly. they are different task using same criteria , How can I clone or copy one criteria that already has numerous restrictions been added ?)