When I'm on the first page of my result list, here's the generated query:
select first 10 books0_.id as id100_...
And everything works fine. However, on the second page I get the following error:
org.hibernate.exception.GenericJDBCException: ResultSet Type is TYPE_FORWARD_ONLY.
The code for the listing is here:
// calculating paging offset
int perPage = Integer.parseInt(Constants.RESULTS_PER_PAGE);
int firstResult = (page == null) ? 0 : (page - 1) * perPage;
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Books> criteria = builder.createQuery(Books.class);
Root<Books> entityRoot = criteria.from(Books.class);
criteria.select(entityRoot);
// constructing list of parameters
List<Predicate> predicates = new ArrayList<Predicate>();
...
// add the list of parameters
criteria.where(builder.and(predicates.toArray(new Predicate[]{})));
//execute query and paginate results
TypedQuery<Books> listQuery = em.createQuery(criteria);
listQuery.setFirstResult(firstResult);
listQuery.setMaxResults(perPage);
return listQuery.getResultList();
And the generated query for the second query is:
select first 20 books0_.id as id100_...
when it should be skip 10 first 10
. How can I use the JPA paging methods now?
I'm using JBoss 7.1
, Spring 3.2
, Hibernate 4.0.1
and Informix 11.70
.