This is the Beginning of the End of the N+1 Problem: Introducing Single Query Loading.
TL;DR:
Starting with Spring Data JDBC 3.2.0-M2, Spring Data JDBC supports Single Query Loading. Single Query Loading loads arbitrary aggregates with a single select statement.
To enable Single Query Loading you need to call setSingleQueryLoadingEnabled(true)
on your RelationalMappingContext
.
In 3.2.0-M2, this works only for simple aggregates, consisting of an aggregate root and a single collection of other entities.
It is also limited to the findAll
, findById
, and findAllByIds
methods in CrudRepository
.
Future versions will improve on that.
A final limitation is that the database you use has to support analytic functions (AKA window functions).
All the officially supported databases except…