-->
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.  [ 4 posts ] 
Author Message
 Post subject: Best practice - updating object graphs with surrogate PK
PostPosted: Wed Jul 11, 2007 4:33 pm 
Newbie

Joined: Wed Jul 11, 2007 3:45 pm
Posts: 3
Hi,

I'm using Hibernate3 for persisting POJOs. Each object in the object graph has a surrogate key which is generated using one of the Hibernate ID generation policy. I'm frequently required to update complete object graphs recreated from a different source(and hence it does not have its surrogate(s)) to the DB.

I'm wondering what is the best way to updated such an object graph -

1. Should I fetch the complete object graph from the database and update every property of every persistent object in the graph with values from the non persistent object graph(the one with updated values). This approach would be cumbersome when it comes to handling complex graphs.

2. Fetch respective IDs (using SQL) of object graph and assign them to the non persistent object graph.

Let me know if you have a better approach.

Thanks in advance.
AYB


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 5:14 pm 
Newbie

Joined: Thu Nov 09, 2006 9:42 pm
Posts: 13
You might want to consider doing something tricky with Apache Commons' Bean Utils to help out, but there is no easy way to do this if your objects are persistent but do not have ids. It may also be worthwhile to look into a way to pass the id values between you and the source of the changes.

--
Tim


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 5:38 pm 
Newbie

Joined: Wed Jul 11, 2007 3:45 pm
Posts: 3
It is not possible for the generator of the updated object graph to pass the surrogate ids as it not aware of them. Also the generator will _always_ generate full object graph in case of both insert and update.

Could you plz elaborate on Common Bean Utils approach you suggested.

Thanks,
AYB


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 13, 2007 5:30 pm 
Newbie

Joined: Wed Jul 11, 2007 3:45 pm
Posts: 3
Had a thought, a mix of property naming conventions and reflection can help updating such object graphs in a generic and concise way.


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