I'm using Spring Data REST to expose my Entity's and their relationships. I have a OneToOne relationship between two Entity's and I'm trying to update/change the relationship with PUT and PATCH.
I noticed that Spring Data REST will only allow you to update linked resources - JPA mapped Entity's (OneToMany, ManyToOne, etc) which are also AggregateRoots (has a Repository) - via a PATCH and are ignored with a PUT.
This can be seen in the LinkedAssociationSkippingAssociationHandler class:
if (associationLinks.isLinkableAssociation(association)) {
return;
}
Why is this? What is the reasoning behind this?
Is it because the design wants us to treat the associations as resources themselves as seen in this part of the documentation? I can alter the relationship via a PUT with Content-Type text/uri-list but it feels unnatural and require an additional HTTP request.
From the Spring data REST 2.5.9.RELEASE the associations are not update on PUT request and only update using PATCH.
Changes in version 2.5.9.RELEASE (2017-04-19)
DATAREST-1030 - PATCH requests do not handle links to associations properly.
Other links about this:
DATAREST-1061: PUT-request with application/json media type payload cannot update association @OneToOne by URI
Domain Driven Design and Spring
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With