循环依赖双向@OneToMany JPA关系

给定以下两个实体:


@Entity

public class Goal {

@Id

@GeneratedValue(strategy = GenerationType.IDENTITY)

private Long id;


private String description;


private BigDecimal amount;


@Email

private String email;


@Email

private 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

}


@Entity

public 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。我想念什么?


红糖糍粑
浏览 298回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java