Reputation:
I have a table with over 10 000 rows. I am using Spring with JPA and i want to make a "batch" job where i can fetch 500 rows at time until there is no more to get from the table? I have a repository class which extends JpaRepository<SchoolAdmin, Long>
.
I am new to Spring so i would appreciate if anyone can help me?
Thank you :)
Upvotes: 2
Views: 711
Reputation: 7279
You should try something like this:
public interface SchoolAdminRepository extends PagingAndSortingRepository< SchoolAdmin, Long> {
List<SchoolAdmin> findAll(Pageable pageable);
}
Then call method providing a Pageable
object:
List<SchoolAdmin> page = repository.findAll(PageRequest.of(pageNumber, 500));
Upvotes: 1