我在下面创建了一些域。
@Entity
public class Conference {
...
@OneToMany(
targetEntity = ProgramDate.class,
mappedBy = "conference",
cascade = CascadeType.REMOVE,
fetch = FetchType.EAGER
)
@JsonBackReference
private List<ProgramDate> programDateList;
}
@Entity
public class Program {
...
@ManyToOne
@JoinColumn(name = "program_date_id")
@JsonBackReference
private ProgramDate date;
@ManyToOne
@JoinColumn(name = "room_id")
private Room room;
...
}
@Entity
public class ProgramDate {
...
@OneToMany(
targetEntity = Program.class,
mappedBy = "date",
fetch = FetchType.EAGER
)
@JsonBackReference
private List<Program> programList;
@ManyToOne
@JoinColumn(name = "conference_id")
private Conference conference;
}
@Entity
public class Room {
...
@OneToMany(
targetEntity = Program.class,
mappedBy = "room",
fetch = FetchType.EAGER
)
@JsonBackReference
private List<Program> programList;
}
我制作了像下面的代码一样的 freemarker。
<#list conference.programDateList as date>
...
</#list>
我遇到一个问题,即 JPA OneToMany、ManyToOne 关系的无限递归引用。我尝试添加 @JsonBackReference
,但它只解决了 json 递归问题。
最佳答案
使用 json 忽略注释:
@OneToMany(
targetEntity = Program.class,
mappedBy = "date",
fetch = FetchType.EAGER
)
@JsonIgnore
private List<Program> programList;
关于java - JPA OneToMany、ManyToOne 关系的无限递归引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36845258/