I have a Java application where we use spring data JPA to query our oracle database. For one use case, I need to fetch all the records present in the table. Now the table has record count of 400,000 thousand and it might grow in the near future. I don't feel comfortable pulling all records into the JVM since we don't know how large they can be. So, I want to configure the code to fetch specific number of records at a time say 50,000 and process before it goes to next 50,000. Is there a way I can achieve this with JPA? I came across this JDBC property that can be used with hibernate hibernate.jdbc.fetch_size
. What I am trying to understand is if I use repository.findAll()
returning List<Entity>
How can a fetch Size work in this case? because List will have all the entities. I was also looking into repository methods returning Stream<>
, not sure if I have to use that. Please do suggest. If there can be better solution for this use case?
Thanks