-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: BiDirectional Circular Reference for only 1 object
PostPosted: Tue Nov 25, 2008 2:29 pm 
Newbie

Joined: Tue Nov 25, 2008 2:24 pm
Posts: 2
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.