问题描述
我正在使用Spring Data REST公开我的实体及其关系.我在两个实体之间有一个OneToOne关系,我正在尝试更新/更改与PUT和PATCH的关系.
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.
我注意到Spring Data REST仅允许您通过更新链接资源-Jem映射的实体(OneToMany,ManyToOne等),它们也是AggregateRoots(具有存储库). PATCH ,并被 PUT 忽略.
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.
这可以在 LinkedAssociationSkippingAssociationHandler 类:
if (associationLinks.isLinkableAssociation(association)) {
return;
}
这是为什么?背后的原因是什么?
Why is this? What is the reasoning behind this?
是因为设计希望我们将关联视为资源本身,如文档的这一部分?我可以通过带有Content-Type文本/uri-list的PUT来改变这种关系,但这感觉很不自然,并且需要额外的HTTP请求.
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.
推荐答案
从Spring数据REST 2.5.9.RELEASE起,关联不会根据PUT请求进行更新,而仅使用PATCH进行更新.
From the Spring data REST 2.5.9.RELEASE the associations are not update on PUT request and only update using PATCH.
版本2.5.9.RELEASE中的更改(2017-04-19)
Changes in version 2.5.9.RELEASE (2017-04-19)
DATAREST-1030-无法处理PATCH请求正确链接到关联.
与此有关的其他链接:
DATAREST-1061:具有应用程序/json媒体类型有效负载的PUT请求无法更新关联@OneToOne通过URI
这篇关于Spring Data Rest PUT诉PATCH LinkableResources的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!