I am using spring boot(2.2.1) along with spring data jpa.
My application has a scheduled service running where I have to read millions of customer data(with pagination) for multiple companies.
And after doing some operation I have to update a status column for those users.
To update status I am using native query (using @Query
annotation and nativeQuery=true
).
public void scheduledTask() {
List<Integer> companies = getCompanies();
for each company:
1. get x customers
2. do some operation
3. repeat step 1 -> 2 for all customers in a company
and then update the read status for the customers
}
After processing some customer records the read status is not getting updated for the processed records if there's any exception.
Also, if there are few million customer records processed hibernate entity manager
gets closed.
In the above process execution, read status gets updated only after processing of all customers of all companies.
Now, I want to know if there's any efficient way to load and update the customer's data so that in case of exception my read status update does not get lost.