【发布时间】:2017-05-09 14:39:27
【问题描述】:
我在玩Spring Data examples。我已经定义了一个实体 Parent,它具有一组关联的 Child 实体。
@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 时,我遇到了错误 Could not read JSON document: Failed to convert from type [java.net.URI] to type 也描述了 here。该问题的答案表明,子实体需要先发布,然后使用返回的 URL。这与 Oliver Gierke 在 this answer 中描述的过程相同。
有没有办法配置 Spring Data 以反序列化完整的子实体?
【问题讨论】:
标签: java spring-data spring-data-rest