i'm trying to solve infinity recursion issue with no success ! project: spring boot and postgresql
i have 3 entities : course, course outline and course schedule :
public class Course implements Serializable {
private static final long serialVersionUID = -6645577819394287204L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private UUID id;
@OneToMany(mappedBy = "course", cascade = CascadeType.REMOVE)
@OrderBy("rank ASC")
private List<CourseOutline> outlines;
....
}
public class CourseOutline implements Serializable {
private static final long serialVersionUID = -6645577819394287204L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private UUID id;
@ManyToOne
@JoinColumn(name = "course", nullable = false)
@JsonIgnore
private Course course;
private Integer rank;
@OneToMany(mappedBy = "outline", cascade = CascadeType.REMOVE)
@OrderBy("day DESC, started ASC")
private Set<CourseSchedule> schedules;
...
}
public class CourseSchedule implements Serializable {
private static final long serialVersionUID = -6645577819394287204L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private UUID id;
@ManyToOne
@JoinColumn(name = "instructor", nullable = true)
@JsonManagedReference
private Person instructor;
@ManyToOne
@JoinColumn(name = "outline", nullable = false)
@JsonIgnore
private CourseOutline outline;
...
}
in REST API i make a call to retrieve a List of CourseOutline by course using CourseOutline Repository :
List<CourseOutline> findAllByCourse(Course course);
but i get below error :
Could not write JSON: Infinite recursion (StackOverflowError); nested
exception is com.fasterxml.jackson.databind.JsonMappingException:
Infinite recursion (StackOverflowError) (through reference chain:
java.util.ArrayList[2]-myDomain.api.models.entities.CourseOutline[\"schedules\"])"