It can be a problem in "transient state": Parent p = new Parent(); Child c = new Child(); c.setParent(p); assertTrue("parent must have a child", p.getChildren() != 0 );
there are two possible solutions : 1) implement "void setParent(Parent p){ this.p = p; p.getChildren().add(this); }" manualy; 2) code generation and "abstract" managed methods ( "transparence" ). I prefer "transparence", but it needs "Factory" if implementation is generated at runtime or JDO style postprocessing if "new" is used to create transient instances. ----- Original Message ----- From: "Max Rydahl Andersen" <[EMAIL PROTECTED]> To: "hibernate list" <[EMAIL PROTECTED]> Sent: Sunday, December 01, 2002 4:26 PM Subject: Re: [Hibernate] Hibernate vs. Castor example > > P.S. I'm not keen on the way you add items to bidirectional association. > The > > correct idiom is: > > > > parent.getChildren().add(child); file://yes, even if the children > collection is > > readonly="true" > > child.setParent(parent); > > sess.save(child); > > > > omitting the first line could cause bugs in more complicated > circumstances. > > Hmm - isn't this idiom inefficient ? > Doesn't parent.getChildren().add() (or any method on the collection) result > in loading all the children ? > > If the only intention is to add the child to the parent shouldn't the > child.setParent(parent) be enough ? > > And then if I wish to have the parent in a "correct" state then I just do a > s.load(parent, parent.getId()) ? > > /max > > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > hibernate-devel mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/hibernate-devel ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel