-->
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.  [ 7 posts ] 
Author Message
 Post subject: Bidirectional mapping using List?
PostPosted: Fri Dec 09, 2005 12:27 pm 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
I found the following statement in the documentation:

Quote:
Please note that Hibernate does not support bidirectional one-to-many associations with an indexed collection (list, map or array) as the "many" end, you have to use a set or bag mapping.


Can anyone explain WHY? I want to have objectA have an ordered collection of objectB but be able to find the parent objectA of any given objectB. Is this not possible? Or have I misunderstood the statement?

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 1:02 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
Yes, I'd also like to hear clarification on this. I've set up a one-to-many using <map>, where the elements have a reference back to their "parent", and simple testing (add parent, add elements, delete elements) revealed no issues ...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 8:13 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
The reason is that the child object doesn't know its index in the parent's collection, so it can't update its table record correctly. In Hibernate 3 they solved it, I believe, by traversing all collections known to the session and looking in them for the object, but Hibernate 2.1 (and NH) doesn't do it.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 5:24 am 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
So if the child's reference to the parent was never updated there wouldn't be a problem?

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 6:41 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
I think there won't be a problem, but I never tried :)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 12:01 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
The child doesn't know it's index in the collection? I'm confused. <map> gives you an IDictionary. The index is a child property used for the DictionaryEntry key (or at least I set it up that way). :?:


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 5:28 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
All right, but how is NHibernate supposed to know this? And what about cases where there isn't such a property in the child?


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

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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.