2
votes

I have 100 records in a database table with a specific status X. I want to fetch all the records using pagination say of pagesize 10. During processing of the fetched records, on some conditions, the records will be updated to status Y. However, if some conditions are not met, the status will not be updated and the record will be skipped. I am doing this using pageable object of Spring Data JPA.

Pageable  pageable =  PageRequest.of(0, 10);

Because of the update to a column, I think every time I get the next set of records in the page 0 itself. The issue is: Because some records can remain without being updated, after say when 10 records went without an update, those 10 records keep coming in the page 0, and I am never able to fetch the remaining records.

Please advice how to fetch records using pagination when there is an update involved.

1
Are you incresing the page on every pass?Robert Niestroj
No, I am not. If i increase, it will skip the next batch. I have kept it constant at 0.Guru

1 Answers

3
votes

I would load upfront all id's of the rows that i want to process. That id's i would partition into buckets of 10. And the fetch the rows by the ID's with: findAllById(Iterable<ID> ids). This way no matter if rows were updated or not you will process all rows.