-->
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: parent/child relationship
PostPosted: Thu May 19, 2005 1:01 pm 
Newbie

Joined: Thu May 19, 2005 11:59 am
Posts: 1
I just realized that in a 1-* relationship, hibernate does not offer many options other than what is exposed in section 22.2 of doc 3.0.3. those options would be :
- a unidirectional 1-* (cf section 8.2.3 - really not recommended)
- composite elements (cf section 22.5 - unfortunately, there are 2 big limitations to composite element classes ...)

so in the end, working with 1-* in hibernate means :
- one-to-many in the parent with inverse=true
- many-to-one in child
- a collection in the parent class, and a backpointer in the child class

the application is then in charge of maintaining the cohesion between the collection and the backpointer, which means :
- either not forgetting to do both a) manipulating collection and b) setting backpointer accordingly in child (cf section 23.3). this can be tricky considering that is something the developer as to remember for every write action that involves the collection : add, remove, set, retain, iterate and remove or set
- or implement some helper methods on the owning class to do the work for you (cf section 22.2): p.addChild(c). but then you would limit what you can with the list; plus you would want a special iterator to be returned when calling Parent.iteratorChild() so that you can intercept the set and remove actions on the iterator.

I would really want Hibernate to recognize that when I have a 1-*, and assuming that in my application I do not have a need to navigate from the child to the parent, a collection in the parent should be enough.

this sounds like an odd constraint to require the object model to provide bidirectionality and ask the application to ensure cohesion, specially when the application has no need for bidirectionality (ie: I just want my parents to hold a collection of my children) and considering that 1-* probably count for 50% of all relationships.

am I just too idealistic, or is there a technical challenge behind this constraint?


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