1

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.

  • what is the initial value of page? Where do you initialize/set this value? – Nabeel Aug 15 '13 at 12:29
  • Its `page=0` the first time. The RESULTS_PER_PAGE is 10. There is nothing wrong with the calculating of the pages, it works when I use native queries with `SKIP` and `FIRST`. –  Aug 15 '13 at 12:31
  • You can look at following example to achieve same using criteria builder. http://stackoverflow.com/questions/10144487/jpa-paging-with-numbers-and-next-previous – Nabeel Aug 15 '13 at 12:36

1 Answers1

1

Unfortunately, Hibernate team is not updating dialect for Informix DBMS for quite some time, so InformixDialect in hibernate distribution doesn't support SKIP feature. Hibernate JIRA is having issue for updating InformixDialect HHH-5414 with patch supplied (opened for more than three years).

You could try to replace InformixDialect class with one from IIUG site. Simply put that file in your project in respectful package directory and try it out.