Spring Data Rest PUT v.s PATCH LinkableResources

。_饼干妹妹 提交于 2019-12-30 02:17:09

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/45442419/spring-data-rest-put-v-s-patch-linkableresources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!