I use the Java code instead of Hibernate to keep the parent-child relationship. For example suppose I have such a relationship Parent-->Level1-->Level2 The class implementation could be like this
public class parent { public void setChild(Level1 child){ if (child.getParent()==null) child.setParent(this); ... } } //this class is a component right now. public class Level1 { public void setChild(Level2 child){ if (child.parent()==null) child.setParent(this); ... } } This implementation has two advantages: 1) you does not rely the <parent> tag for parent-child relationship mapping. 2) notice the following function call. Parent p=new Parent(); Level1 c=new Level1(); p.setChild(c); //the following call is not necessary with the above implementation. //c.setParent(p) Session.save(p); Of course, this is a workaround. jason. --- Viktor Szathmary <[EMAIL PROTECTED]> wrote: > hi, > > On Fri, 31 Jan 2003 16:02:49 +1100, > [EMAIL PROTECTED] said: > > > > private void setTopParent(TopLevelParent > topParent) { > > this.parent = topParent.getComponent(); > > } > > > > > > should do what you need ;) > > ok, it does not :) unfortunately the call sequence > is: > > - nestedChild.setParent( toplevel ) > - nested.setParent( toplevel ) > - toplevel.setChild( nested ) > > so, at the point when the nestedChild's parent > relationship is > estabilished, the toplevel object's downward > relationships are not > established yet. > > furthermore this whole thing makes things uglier, > since as far the object > model is concerned, a child now needs to have > dependencies on it's > toplevel parent (but this relationship might not > even be fixed). also, > due the the quirk i described above, the nested > child would need to keep > a reference to the toplevel object, so it can do > late binding... > > alltogether, i think the more useful behavior for > composite-element > parents' would be setting the immediate parent. > perhaps make it an > option... or pick based on the class specified, eg. > <parent name="foo" > class="foo.bar.Baz"/>. > > best regards, > viktor > > -- > http://fastmail.fm - Does exactly what it says on > the tin > > > ------------------------------------------------------- > This SF.NET email is sponsored by: > SourceForge Enterprise Edition + IBM + LinuxWorld = > Something 2 See! > http://www.vasoftware.com > _______________________________________________ > hibernate-devel mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/hibernate-devel __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com ------------------------------------------------------- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.com _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel