-->
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: Copying an object graph
PostPosted: Thu May 19, 2011 6:10 pm 
Beginner
Beginner

Joined: Mon Jul 28, 2008 4:36 pm
Posts: 24
I'm trying to copy a graph of 34 different kinds of objects which form a variety of lattices, trees, and other relationships. The copy has to work on a single server as well as across different servers connected to other databases (with the same schema and Java classes with identical SerialVersionUids). My most promising method to date is to load the whole graph into memory (probably max 50MB), then serialize it. This part works, though I haven't initialized absolutely everything and there are a few PersistentSets and AbstractPersistantCollections and AbstractComponentTypes in my serialized file. Will those blow up if I send them to a different server? That's not the only problem...

On the other side, I read the file in and do a hiberSession.save(parent) with all my hibernate-mappings set to default-cascade="save-update" and at first I thought it worked. But when I looked closer, it had saved the new parent, but moved everything from the old parent over to the new one! It looks like I'm going to have to save the parent with no cascade, then get the new parent ID, and set the parent ID on every child before I save it, using a similar method all the way through the graph of objects.

Without the serialization, I've done it that way before, keeping hash tables of old vs. new objects or object IDs. But it involves a lot of opening and closing sessions, keeping track of detached (old) and transient (ancestor) objects, etc. It's prone to error when I add a new table or column to the database. I can do that if I have to, but I thought I'd ask here if anyone has done this before and knows of an easier way?

Any thoughts, suggestions, or advice would be appreciated.


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.