0
我在玩Spring Data examples。我已經定義了一個實體Parent,它有一組關聯的子實體。用Spring Data在一個請求中發佈子實體
@Entity
@Table
@Data
public class Parent {
@Id
@GeneratedValue
private Integer id;
@NotNull
private String name;
@Fetch(FetchMode.SUBSELECT)
@OneToMany(fetch = EAGER, cascade = {ALL}, orphanRemoval = true)
private Set<Child> childs;
}
@Entity
@Table
@Data
public class Item {
@Id
@GeneratedValue
private Integer id;
@NotNull
private String name;
}
和相應的存儲庫。我的問題是,當使用curl發佈帶有Child
的新Parent
時,我遇到了也描述爲here的錯誤Could not read JSON document: Failed to convert from type [java.net.URI] to type
。該問題的答案指出,子實體需要在之前發佈,然後使用返回的URL。這與Oliver Gierke在this answer中描述的過程相同。
有什麼辦法配置Spring數據來反序列化完整的子實體嗎?