Issue
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?
Solution
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.
Answered By - Steven Chris
Answer Checked By - David Goodson (JavaFixing Volunteer)