Are they exist some methods to handle pagination for update? For example i have 100 rows of type:
@Id
private Integer id;
@Column
private boolean flag;
@Column
private Date last;
In start they looks like: id, false, null
And i have method in persistence:
@Query("SELECT t FROM Test t WHERE (t.last < :processStart OR t.last IS NULL)")
Page<Test> find(Pageable pageable, @Param("processStart") Date processStart);
I need take 10, set flag true and last = new Date() for each and save it back to DB.
Implementation looks like:
Date start = new Date();
for (int i = 0; i < 10; i++) {
Pageable request = new PageRequest(i, 10, SortDirectuin.ASC, "id");
Page page = testPersistence.find(request, start);
page.getContext().forEach(t -> {
..huge part of another operation..
t.setFlag(true);
t.setLast(new Date());
testPersistence.save(t);
});
}
First page context should be with id: 0..9; Second: 10..19;
But in my case second page returns with id: 20..29;
And in end of pagination i lost half of data. Returns: 0..9, 20..29, 40..49, etc.
How to prevent this?