-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Limit selection of nested properties #3352
Comments
Currently, this behavior is by design as we use top-level properties for the selection. We could introspect the projection for nested projections to limit the selection. For the time being, using inlined, concatenated properties makes sense. We can revisit this enhancement somewhere in the future. |
Thank you for the feedback, @mp911de! Would you accept a small addition to the docs about it? I'd be happy to contribute. Talking with colleagues, I realized this wasn't clear to many of them when looking at the |
Would love to see this revisited in the future - if the nested entity has relationships itself that are not part of the projection, they will also get queried in separate queries, so this can result in a lot of wasted DB resources. |
I'm not sure if I should report this in
spring-data-jpa
orspring-data-commons
. I apologize in advance if this isn't the right place.I experienced the following issue on Spring Data JPA with Hibernate, initially with Spring Boot 2.7.14 and Db2 for z/OS, but also reproduced with the latest Spring Boot (both GA and snapshot) and H2.
In the Interface-based Projections section of both the Spring Data JPA and Spring Data Commons reference guides, there is an example on how to use such projections recursively:
If I use this interface in a repository, like:
The following query is executed:
where
street
andzip_code
are also selected although they are not required.This seems to contradict what is mentioned in the Closed Projections section:
As a workaround, if I remove the nested interface in
PersonSummary
and concatenate the property names:the following query is executed:
Reproducer: PersonRepositoryTest
Is this a bug or is it by design?
In case the example with the nested interface is not meant to be considered as a closed projection, would it make sense to highlight this detail in the documentation?
The text was updated successfully, but these errors were encountered: