JPA many-to-many relationship causing infinite recursion and stack overflow error

后端 未结 2 583
青春惊慌失措
青春惊慌失措 2021-02-10 02:02

I\'m working on an EclipseLink project in which one user can \"follow\" another as can be done on social media sites. I have this set up with a User entity (referen

2条回答
  •  有刺的猬
    2021-02-10 02:38

    Every time you have @OneToMany (a collection) you need to add @JsonIgnore to it or else it will cause an infinite loop which results in a stack overflow exception because it keeps looking up between the parent(the one side) and the child (the many side) For more info on dealing with this kind of problems check this excellent article http://www.baeldung.com/jackson-bidirectional-relationships-and-infinite-recursion

提交回复
热议问题