Skip to content

Implicit join on one-to-many relations #1330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
petromir opened this issue Sep 19, 2022 · 5 comments
Closed

Implicit join on one-to-many relations #1330

petromir opened this issue Sep 19, 2022 · 5 comments
Labels
in: jdbc Spring Data JDBC status: duplicate A duplicate of another issue type: enhancement A general enhancement

Comments

@petromir
Copy link

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 19, 2022
@schauder
Copy link
Contributor

We are working on a more efficient way to load aggregates.

@schauder schauder added in: jdbc Spring Data JDBC and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 19, 2022
@petromir
Copy link
Author

@schauder Is there another ticket related to this activity?

@benzen
Copy link

benzen commented 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
Copy link

benzen commented Nov 29, 2022

@petromir Found this ticket which was created in 2019
#592

@schauder
Copy link
Contributor

duplicate of #592

@schauder schauder closed this as not planned Won't fix, can't repro, duplicate, stale Nov 30, 2022
@schauder schauder added type: enhancement A general enhancement status: duplicate A duplicate of another issue labels Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: jdbc Spring Data JDBC status: duplicate A duplicate of another issue type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants