I have an Object Case which can link to other Cases. I have a linking table with two id columns and the annotation for defining the manytomany relationship -
Code:
@ManyToMany(fetch=FetchType.LAZY, cascade={CascadeType.MERGE, CascadeType.PERSIST})
@JoinTable(
name="Case_Case",
joinColumns=@JoinColumn(name="parentId"),
inverseJoinColumns=@JoinColumn(name="childId")
)
private List<Case> cases;
Now lets say I have 3 cases with Ids 1,2,3 and Case 1 links to cases 2 and 3. If I have case 1 I can call getCases() and it will display cases 2 and 3. However, the inverse is not true - if I am on case 3 and call getCases I will not receive case 1.
To do this must I add the inverse direction to my table as well? Or is it possible to retrieve the inverse by using getCases? Obviously I could setup another property that maps the inverse relationship but now I will have 2 sets of lists instead of 1 list which contains all links.