-->
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.  [ 5 posts ] 
Author Message
 Post subject: Migrating data from a staging DB part II
PostPosted: Mon Apr 25, 2005 4:24 am 
Newbie

Joined: Tue Jan 11, 2005 12:47 pm
Posts: 5
Hi,

I posted a question on Friday regarding data migration and have since found a similar unanswered post from the beginning of September.

I've got fairly close to a solution but it's pretty hairy and if there's a better way to achieve what I'm trying to do, I'd love to hear some suggestions.

Basically all that I want to do is migrate data from one database to another. During testing, I have test DB but, all going well, I'd like to migrate the data generated during testing across to another DB where it will be stored more permanently. Same DB provider and same schema.

I guess what I need to do is load all persistent objects in using Session Factory A (configured to use the test DB) then convince hibernate that it's never seen the objects before and save them using Session Factory B (configured to use the release DB).

It's the "convince hibernate that it's never seen the objects before" bit I'm struggling with.

I'm currently using reflection to introspect all of the objects and set 'id' fields to null. Just about working but a few complications with array attributes and various other nasties.

This does however seem very similar to what hibernate does when initially determining whether a saveOrUpdate is required and if there's another way to do it, it would be preferable to hand coding.

The same problem would need to be solved when moving from one DB vendor to another so I'm hoping there's a more obvious way to do this that I've not stumbled upon.

Cheers,
Jeremy.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 25, 2005 6:51 am 
Newbie

Joined: Tue Jan 11, 2005 12:47 pm
Posts: 5
Just some additional information.
The replicate() method is almost what I'm looking for in that it will allow me to save the data if there aren't any conflicting ids.

After a couple of test data->release data migrations I'm going to run into problems when replicating data with the same id.

I think that what I need is a detached -> transient state change.

Any offers?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 26, 2005 12:16 pm 
Newbie

Joined: Tue Jan 11, 2005 12:47 pm
Posts: 5
Okeydoke.

Utilising some very messy introspection I've managed to null out most of the IDs in my classes. Where I've succeeded, I've got the required behaviour.

Unfortunately the plethora of exceptional cases along the lines of:

Code:
IF processing a hibernate substitued collection AND the contents happen to be mapped as values rather than entities
THEN mark the collection as dirty so that the contents are saved when the parent instance is saved in the new Session


is proving damaging to my health.

I can't be the only person to have tried to migrate data from one database to another...What's the secret?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 4:14 pm 
I don't know been strugling myself. Setting ids to -1 and another "solution" being having assigned as primary key generator and then using replicate()


Top
  
 
 Post subject:
PostPosted: Fri Apr 29, 2005 8:07 am 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
I have no idea if this would work, but could you set an interceptor on the second database Session/Configuration to null out any id fields on save? (I qualify this by saying I haven't looked to see whether onSave is called before or after the save vs. update decision has been made).


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