-->
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.  [ 3 posts ] 
Author Message
 Post subject: Associating existing child objects with parent by ids?
PostPosted: Thu Jul 21, 2005 3:31 pm 
Beginner
Beginner

Joined: Wed Jul 21, 2004 6:50 pm
Posts: 27
Hi,

I have a situation where I have a lot of existing objects in the database that get created elsewhere.

I have other objects which have a one-to-many relationship with these child objects. They are defined as a List association in the parent, and mapped in the database through a link table.

I really don't want to load all the child objects, add them to the parent, and then save the parent to link them together. But getting the child id's for the parent, and saving them directly to the link table with teh parent id, seems wrong.

What is the Hibernate way to do this?

cheers,

David


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 4:46 pm 
Beginner
Beginner

Joined: Wed Jul 21, 2004 6:50 pm
Posts: 27
Does anyone have any idea on this, please?

cheers,

David


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 5:22 pm 
Regular
Regular

Joined: Thu May 26, 2005 12:20 am
Posts: 72
Let me see if I understand what you are trying to do:

You have objects that get created elsewhere, but whatever creates them does not create the linking table entry?

In that case, I see three options (two you mentioned):

1. load the unassociated Java objects, link them, and persist (you said)
2. do direct SQL on the link table to update (you said)
2a. this could be done in the application as JDBC, or..
2b. this could be handled as DB triggers or DB job if there is an automated way to do it.
3. have the external applications that create the objects create the relation. (This could be combined with 2b maybe)

(1) does seem to be the hibernate way. The reason it seems so funky is that your data is being manipluated outside the app and left in a somewhat inconsistant state.

(2) seems fine to me, unless you need application GUI to handle things

(3) if possible seems the best in terms of data consistancy, imho
or (2b) if you cannot count on the other applications

dan


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