I've got a simple @ManyToMany relationship I'm trying to capture, but I keep running into an infinite cycle problem.
I've got three classes kind of like this: Person, Issue, IssuePosition
Each person can have a position on any issue and can have positions against different issues. Positions are things like "for" "against" "neutral"
Issues are things like "increasing taxes" "building a new school"
Right now I've got in the Person class:
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "person", fetch = FetchType.EAGER)
@Fetch(FetchMode.SUBSELECT)
private List<IssuePosition> issuePositions = new ArrayList<IssuePosition>();
and in the Issue class:
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "issue", fetch = FetchType.EAGER)
private List<IssuePosition> issuePositions = new ArrayList<IssuePosition>();
in the IssuePosition class:
@ManyToOne(optional = true)
private Issue issue;
@ManyToOne(optional = true)
private Person person;
This causes a call to load the Person to load the IssuePositions which loads the Issues which loads the IssuePositions which loads the Person.
How do I stop this? I've removed the fetch=FetchType.EAGER but that didn't help
This tutorial provides a good example of how to use the
@ManyToMany
annotation to map a relationship using a@JoinTable
. Here's a slightly more complicated example.