1 回答
TA贡献1829条经验 获得超4个赞
通过写这个问题,我找到了解决方案,所以我分享一下:
使用@JsonManagedReference
和@JsonBackReference
注释。
public class First {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String code;
private String name;
private String groupe;
@OneToMany(mappedBy = "first", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JsonManagedReference
private List<Second> listLiens;
}
public class Second {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String type;
private String link;
@ManyToOne(fetch = FetchType.EAGER)
@JsonBackReference
@JoinColumn(name = "first_id", nullable = false)
private First first;
}
添加回答
举报