-->
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: Creating a Child with Parent's Foreign Key Value
PostPosted: Fri Aug 04, 2006 12:19 pm 
Newbie

Joined: Fri Aug 04, 2006 11:56 am
Posts: 9
Location: Wilmington, DE
I'm trying to create a child object that is linked to a parent object. The problem is I am attempting to retrofit this into an application that used a lot of SQL SPs and at the point where I create the object I only have the value of the Parent's unique ID, not the whole object.

What is the best practice for creating the child object? Do I need to lookup the parent first? It seems a bit silly since I know all that will get put in the child table is the FK value that I've got. I did some searches but didn't come up with anything.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 05, 2006 4:42 pm 
Senior
Senior

Joined: Sat Nov 27, 2004 4:13 am
Posts: 137
we've done such thing in our applications lots of time, just do as this:

Code:
Parent parent = new Parent();  // you have the default constructor
parent.setId(providedParentId);

child.setParent(parent);

session.save(child);


Hibernate just uses the parent's ID for creating the relationship if cascade attribute does not contain UPDATE.

_________________
don't forget to credit!

Amir Pashazadeh
Payeshgaran MT
پايشگران مديريت طرح
http://www.payeshgaran.co
http://www.payeshgaran.org
http://www.payeshgaran.net


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.