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 loading/saving
PostPosted: Tue Sep 04, 2007 9:44 am 
Beginner
Beginner

Joined: Thu Apr 12, 2007 10:38 am
Posts: 22
Hi

I'm going through the examples for parent/child relationships here http://www.hibernate.org/hib_docs/refer ... child.html

..and it made me wonder about something. If I have a parent object, but I only have the id of my child object, do I need to look up the child object before saving the parent?

E.g. (pseudocode)

Code:
Parent contains Child
Parent p ....;              // fully populated by some means
long childId = 123;    // perhaps passed in via a form in a JSP
p.setChild(xxxxxx);
getHibernateTemplate().save(p)


So my question is, whats the best way of filling 'xxxx'. Is it enough to do

Code:
Child c = new Child();
c.setId(childId)
p.setChild(c)


and let hibernate do the rest

Or do I have to look up the child myself and give hibernate the fully retrieved object?

Code:
Child c = getHibernateTemplate().get(....);
p.setChild(c);


Thanks


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.