当我在结果列表的第一页时,生成的查询如下:
select first 10 books0_.id as id100_...
一切正常。但是,在第二页上,我收到以下错误:
org.hibernate.exception.GenericJDBCException: ResultSet Type is TYPE_FORWARD_ONLY.
清单的代码在这里:
// 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();
第二个查询的生成查询是:
select first 20 books0_.id as id100_...
什么时候应该skip 10 first 10
。我现在如何使用 JPA 分页方法?
我正在使用JBoss 7.1
,Spring 3.2
和.Hibernate 4.0.1
Informix 11.70