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;
}
添加回答
舉報