Let's say I need to get 10 entities from the database using the listIds. If I get from DB each entity by id using listIds.stream -> repository.findById(id), it works faster than findAllById(listIds) why is this happening?
val listIds = List.of(1,2,3,4,5,6,7,8,9,10);
// example faster:
val entityList = listIds
.stream()
.map(id -> repository.findById(id).orElseThrow())
.collect(Collectors.toList());
// example slower
val entityList = repository.findAllById(listIds);
the two examples are not executed in the same transaction, they are just different implementations of the method