You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider an entity with a lazy-loaded one-to-many association, and a simple shallow projection that excludes the association. When retrieving the entity collection with the shallow projection, we would hope and expect that the association is never loaded.
In practice, SDR forces loading of the association via the EmbeddedResourcesAssembler's getEmbeddedResources method. This can become a significant performance problem in complex entity networks with many associations and large-scale one-to-many relationships.
I am not 100% clear on the scope of responsibility of the the EmbeddedResourcesAssembler (does it assemble association links, nested response models, or both?), but it is clearly aware of the projection context via its projector member. It can use this to check if the actual value of the association is needed in the projection. If not, then the property fetch done here and the subsequent collection processing can be skipped; all that should be needed is a link to the relevant relation endpoint.
Consider an entity with a lazy-loaded one-to-many association…
That's a mismodeled aggregate in the first place. If the target of the relationship is a non-aggregate, that relationship should be materialized eagerly. If the target is an aggregate in the first place, the relationship should be rather referring to identifiers, not full objects.
In practice, SDR forces loading of the association via the EmbeddedResourcesAssembler's getEmbeddedResources method.
Force is a strong word here, but we somehow need to render the embedded resources when creating the representation.
This can become a significant performance problem in complex entity networks with many associations and large-scale one-to-many relationships.
Especially the latter are an anti-pattern in aggregate design. Remember that Spring Data REST is not an arbitrary “expose your database via JPA and HTTP” tool. It's heavily relying on aggregates being modeled as they, in contrast to relational databases, naturally form trees. That's necessary, as only then we can reason about which relationships are included in the primary representation and which ones to represent as links to other resources.
I.e., you're trying to fix the messenger when the source of the problem is the aggregate design. Large, likely unbounded one-to-many relationships can usually be replaced with an inverted relationship and a findBy$Owner(…) query method on the repository.
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.
Activity
odrotbohm commentedon Jan 15, 2026
That's a mismodeled aggregate in the first place. If the target of the relationship is a non-aggregate, that relationship should be materialized eagerly. If the target is an aggregate in the first place, the relationship should be rather referring to identifiers, not full objects.
Force is a strong word here, but we somehow need to render the embedded resources when creating the representation.
Especially the latter are an anti-pattern in aggregate design. Remember that Spring Data REST is not an arbitrary “expose your database via JPA and HTTP” tool. It's heavily relying on aggregates being modeled as they, in contrast to relational databases, naturally form trees. That's necessary, as only then we can reason about which relationships are included in the primary representation and which ones to represent as links to other resources.
I.e., you're trying to fix the messenger when the source of the problem is the aggregate design. Large, likely unbounded one-to-many relationships can usually be replaced with an inverted relationship and a
findBy$Owner(…)query method on the repository.spring-projects-issues commentedon Jan 22, 2026
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
spring-projects-issues commentedon Jan 29, 2026
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.