JPA:两端都有列表,没有无限循环 [英] JPA: Having lists on both ends without infinite loop

查看:55
本文介绍了JPA:两端都有列表,没有无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过 Set 属性链接两个实体,例如:

I am trying to link two entities via Set properties like:

实体A:

Set<Group> groups

实体B:

Set<Filter> filters

但是,我不断收到无限递归之类的错误.用JPA做到这一点的最佳方法是什么?

However, I keep getting errors like infinite recursions. What is the best way to do this with JPA?

推荐答案

它进入无限递归,因为您的两个实体相互调用,并且永远不会停止.尝试添加

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

@JsonBackReference(value = "user-card")
Set<Filter> filters

位于实体中的两个集合之上.它用于警告spring不要进入无限递归.

above both the sets in your entities. It is used to warn spring not go into infinite recursion.

这篇关于JPA:两端都有列表,没有无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆