Reputation: 389
I made some domains below.
@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;
}
And I made freemarker like below code.
<#list conference.programDateList as date>
...
</#list>
I meet a problem that is infinite recursion reference with JPA OneToMany, ManyToOne Relationship. I try to add @JsonBackReference
, but it only resolved about the json recursive problem.
Upvotes: 1
Views: 2456
Reputation: 566
Use json ignore annotation :
@OneToMany(
targetEntity = Program.class,
mappedBy = "date",
fetch = FetchType.EAGER
)
@JsonIgnore
private List<Program> programList;
Upvotes: 2
Reputation: 613
Why do you include Room & Programdate in Conference, then in Program add a Conference along a Room & a Programdate which should already be contained in Conference ? Then in ProgramDate you have another reference to... conference and a list of program...
Basically you shouldn't try to "hack" out of these loops with some fancy annotations, but you should work on your data model. While Conference looks ok, Program could be a list of conferences only, and a Programdate should be... a date.
Upvotes: 1