Java Spring-发布JSON对象时丢失到父对象的链接
在Angular+Spring应用程序中,我有一个实体Java Spring-发布JSON对象时丢失到父对象的链接,java,json,spring,Java,Json,Spring,在Angular+Spring应用程序中,我有一个实体日志记录,它有一个父项目: @Entity public class Logging implements Identifiable<Integer> { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; private String message; private Date date;
日志记录
,它有一个父项目
:
@Entity
public class Logging implements Identifiable<Integer> {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String message;
private Date date;
@JsonIgnore
@ManyToOne(fetch = FetchType.EAGER)
private Project project;
我现在发布的JSON对象如下所示:
{
id: null
date: "2015-12-27T22:04:20.556Z"
message: "test"
project: {
id: 16616,
// ...
}
}
但我也试过:
{
id: null
date: "2015-12-27T22:04:20.556Z"
message: "test"
project: 16616,
}
在将对象保存到数据库时,如何确保填写了project
的外键
谢谢我通过将此添加到我的实体解决了我的问题:
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
由于循环引用,我还删除了之前添加的JsonIgnore
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")