-->
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.  [ 2 posts ] 
Author Message
 Post subject: is it must to do insert of new parent with childs in 2 steps
PostPosted: Wed Mar 31, 2004 7:08 am 
Regular
Regular

Joined: Fri Nov 21, 2003 10:23 am
Posts: 81
Is it must to do insert of new parent with childs in 2 steps?
1. save(parent) - retrieve generated parentId
2. saveOrUpdate(parent) - add childs to parent and save it

one-to-many mapping
Code:
<set name="children" inverse="true" cascade="all-delete-orphan">
<key column="parent_id"/>
<one-to-many class="Child"/>
</set>


Because code below is not working properly. Because table for Child object have parentId null at the end of code:
Code:
Parent p = new Parent();
Child c = new Child();
c.setParent(p);
p.getChildren().add(c);
session.saveOrUpdate(p);


Code in two steps (this code not fit to session facade):
Code:
Parent p = new Parent();
session.saveOrUpdate(p);
session.flush();
Child c = new Child();
c.setParent(p);
p.getChildren().add(c);
session.saveOrUpdate(p);


Problem with insert in two steps is, that I would like to have SessionBean, that have method store(Parent parent), and I would like to send new parent object together with it's childs to session bean.

Any help how to do it in multitier environment?

Thanks very much.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 7:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Of course you never need to call saveOrUpdate() twice in a single session. Try reading parent/child relationship section again.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.