问题
I am trying to link two entities via Set
properties like:
Entity A:
Set<Group> groups
Entity B:
Set<Filter> filters
However, I keep getting errors like infinite recursions. What is the best way to do this with JPA?
回答1:
It goes into infinite recursion because both your entities call each other and it will never stop. Try adding
@JsonManagedReference(value = "group-filter")
Set<Group> groups
and
@JsonBackReference(value = "user-card")
Set<Filter> filters
above both the sets in your entities. It is used to warn spring not go into infinite recursion.
来源:https://stackoverflow.com/questions/59299430/jpa-having-lists-on-both-ends-without-infinite-loop