Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data Rest PUT v.s PATCH LinkableResources

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.

like image 297
szxnyc Avatar asked Aug 01 '17 15:08

szxnyc


1 Answers

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

like image 95
pdorgambide Avatar answered Nov 14 '22 08:11

pdorgambide