JPA: Having lists on both ends without infinite loop

∥☆過路亽.° 提交于 2021-02-17 05:28:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!