Not planned
Description
I really like the simplicity of spring-data-jdbc, but the default behaviour somehow breaks my understanding of efficient loading.
Problem description
Having one-to-many relations in an aggregate root always causes N+1 queries. There is no way to change this so if I have the following structure, I end up with many redundant SQL statements.
Minion
class Minion {
@Id
Long id;
String firstName;
String lastName;
@MappedCollection(idColumn = "minion_id", keyColumn = "id")
final Set<Toy> toys = new HashSet<>();
}
Toy
class Toy {
@Id
Long id;
String name;
Long minionId;
}
Expected behaviour
Change the default behaviour and load all the relations with implicit join. I assume that the library has the information
Environment
org.springframework.boot:spring-boot-starter:2.5.6
org.springframework.boot:spring-boot-starter-data-jdbc: 2.5.6
org.springframework.data:spring-data-jdbc:2.2.6
Activity
schauder commentedon Sep 19, 2022
We are working on a more efficient way to load aggregates.
petromir commentedon Sep 27, 2022
@schauder Is there another ticket related to this activity?
benzen commentedon Nov 25, 2022
I ended up with the same realisation after turning on sql trace.
Meanwhile what could be done, is using a projection with a custom query.
This help prevent the loading of one-to-many relationship, which help make the system more responsive
benzen commentedon Nov 29, 2022
@petromir Found this ticket which was created in 2019
#592
schauder commentedon Nov 30, 2022
duplicate of #592