Search code examples
javaspringspring-bootjpabackend

What are the best practices for resolving jpa bidirectional circular references?


What are the best practices for resolving JPA bidirectional circular references?

I experienced an error falling into infinite recursion due to JPA bidirectional circular reference.

At this time, it was said that the problem could be solved in the following way.

  1. Ignore using @JsonIgnore -> I ruled out this option because I need all the data.

  2. Use @JsonBackReference, @JsonManagedReference. -> Currently, I have solved my problem using this method.

I'm wondering if there's a better way to solve the problem, so I'm leaving a question like this.

best regards!


Solution

  • @JsonBackReference and @JsonManagedReference are semantically correct.

    @JsonIngore not.

    Checkout this article: https://www.baeldung.com/jackson-bidirectional-relationships-and-infinite-recursion