Infinite loop with spring-boot in a one to many relation

前端 未结 6 1854
梦谈多话
梦谈多话 2021-02-06 09:52

In a rest application, I use spring boot with jpa.

I have a class Lodger

who have

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, m         


        
6条回答
  •  余生分开走
    2021-02-06 10:18

    Solution:

    Use

    @JsonManagedReference annotation for the first objects instantiated

    @JsonBackReference annotation for the second objects instantiated

    First:

    @JsonManagedReference
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "lodger")
        private List referenceList;
    

    Second:

    @JsonBackReference
    @ManyToOne
        @JoinColumn(name = "lodgerId")
        private Lodger lodger;
    

提交回复
热议问题