Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring-发布JSON对象时丢失到父对象的链接_Java_Json_Spring - Fatal编程技术网

Java Spring-发布JSON对象时丢失到父对象的链接

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;

在Angular+Spring应用程序中,我有一个实体
日志记录
,它有一个父
项目

@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")