我需要更新子实体数据。如下所示,Parent
具有多个children
。我可以添加新的孩子,
Parent parent = parentRepo.findById(parentId);
parent.getChild().add(newChild);
现在我的问题是,有什么方法可以更新添加在父级中的现有子级?
父实体
public class Parent implements Serializable {
@Column
private String id;
@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private Set<Child> child;
}
public class Childimplements Serializable {
@Column
private String someData;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id", nullable = false)
private Parent parent;
}