gpt4 book ai didi

mysql - Spring Data REST持久化MySQL一对多内嵌对象更新(PUT/PATCH)

转载 作者:行者123 更新时间:2023-11-30 22:33:19 25 4
gpt4 key购买 nike

我有两个类:Object 和 ObjectProperty,它们是一对多的关系。所以 Object 有一些 ObjectParameters 的 HashSet。

public Set<SOPParameter> parameters = new HashSet<>();

Spring Data REST 完美地执行 POST,但是在 PUT 替换或 PATCH 更新具有特定 id 的对象的情况下,参数根本不受影响。有什么办法可以解决?

最佳答案

回答我自己的问题:首先,注释 orphanRemoval 必须设置为 true

@OneToMany(cascade = {CascadeType.ALL,CascadeType.PERSIST,CascadeType.MERGE}, mappedBy = "sop", orphanRemoval=true)
public Set<SOPParameter> parameters = new HashSet<>();

其次,必须说明 setParameters 的处理程序:


public void setParameters(HashSet<SOPParameter> set) {
if (set != null) {
this.parameters.clear();
this.parameters.addAll(set);
}
}

关于mysql - Spring Data REST持久化MySQL一对多内嵌对象更新(PUT/PATCH),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33253481/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com