Pregunta

I'm using spring 3.2 and Hibernate JPA with oracle 10g configuration. I have to display records of a table in pages of 10 records, which has a total of 28 records presently.

So I prepare a persistence Query and set it's FirstResult and MaxResult:

String sql = "From instanceDetailLog Where formName='GPB' Order By instanceId";
Query query = entityManager.createQuery(sql);

query.setFirstResult(((pageNumber*recordsToFetch)-recordsToFetch));
query.setMaxResults((pageNumber*recordsToFetch));

List<Object> dataList = query.getResultList();

Initially for records 1-10 the records are fetched properly. But When I request for the next page for records 11-20, it gives me 18 records (All of the remaining records) and in the third page I get repeating records.

I had stumbled upon this article. Which describes about an issue with pagination in oracle and JPA.

Can someone please tell me what I'm missing?

¿Fue útil?

Solución

MaxResults should be a constant recordsToFetch. Using pageNumber*recordsToFetch you are telling it to fetch 20 rows, which is why you are getting the last 18.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top