为了账号安全,请及时绑定邮箱和手机立即绑定

循环依赖双向@OneToMany JPA关系

循环依赖双向@OneToMany JPA关系

红糖糍粑 2021-04-09 18:19:03
给定以下两个实体:@Entitypublic class Goal {@Id@GeneratedValue(strategy = GenerationType.IDENTITY)private Long id;private String description;private BigDecimal amount;@Emailprivate String email;@Emailprivate String supervisorEmail;private LocalDateTime deadline;@Enumerated(EnumType.STRING)@Column(nullable = false)private PaymentPurpose purpose;@Enumerated(EnumType.STRING)private GoalStatus status;@ManyToOne(cascade = CascadeType.ALL)private Person person;//getters and setters}和@Entitypublic class Person {    @Id    @GeneratedValue(strategy = GenerationType.IDENTITY)    private Long id;    private String firstName;    private String lastName;    @Email    private String email;    @OneToMany(mappedBy = "person")    private List<Goal> goals;    //getters and setters}当我goalRepository.findAll()在插入带有DummyGoal的Dummy后打电话时Person,我得到了永无止境的递归循环。添加@JsonIgnore到goal列表中Person并没有帮助。我也试过了@JsonIgnoreProperties。我想念什么?
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 297 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信