I have a list of ids that are associated with objects to fetch. I need to process each object after fetching them.
Should I get the list of objects using findAllById, so there will be one DB call and then process the result using for loop?
OR
Should I run the for loop for ids, and process each object using findById? Which seems bad as it will do multiple DB calls.
Is multiple non-nested for loop better than multiple DB calls?
Asked
Active
Viewed 291 times
0

RAHUL VISHWAKARMA
- 27
- 7
-
findAllByIds slower that findById in cicle why? https://stackoverflow.com/questions/75383453/why-findallbyid-is-slower-than-findbyid-in-a-loop-jpa-hibernate-jav – Ilya Slezkin Feb 08 '23 at 09:14
1 Answers
1
Its better using findAllByIds because one DB call and if you want to process each data, you can achieve that by doing loop/foreach/stream
Yes, because it would decrease the minimum of error by creating DB call.

Steven Chris
- 61
- 4