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

前端 未结 6 1851
梦谈多话
梦谈多话 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 09:58

    If you primary keys in both tables are same name for example : id.

    Add this

    @Entity
    @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,property = "id")
    public class User {
        ...
    }
    

    And to Reference class.

    @Entity
    @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,property = "id")
    public class Reference {
        ...
    }
    

提交回复
热议问题