Spring Data Rest PUT v.s PATCH LinkableResources
Asked Answered
L

1

10

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.

Lacrimatory answered 1/8, 2017 at 15:52 Comment(0)
A
6

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

Adder answered 5/10, 2017 at 21:10 Comment(1)
You just confirmed the fact while we still don't understand why PATCH and POST are properly resolve associations but PUT skips them. Anybody can explain it in English?Djokjakarta

© 2022 - 2024 — McMap. All rights reserved.