How to fetch lazy attributes in collection of entities, by not doing N calls to database. Example:
transactions = getTransactionsBySomeCriteriaApiQuery(..); // n transactions
// this make 3*n calls to DB, I want to do only a few calls
transactions.forEach(res -> {
res.getLazyCollection1().size();
res.getLazyCollection2().size();
res.getLazyCollection3().size();
});
return transactions;
Assume n is big number. I would like to know if it is possible to fetch that lazy data by not making huge amount of calls to DB. I am using JPA (eclipselink), relational database.
EDIT: Indeed it is N+1 selects problem, and i would like to know how it can be resolved in eclipselink. Note that I do not want to change entity mappings from lazy to eager, because it is needed in other places. I have tried to use fetch joins (fetch on criteriaAPI), but this not working when used more than one.