-->
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.  [ 7 posts ] 
Author Message
 Post subject: best practice for migrating data between databases
PostPosted: Thu Nov 22, 2007 6:21 am 
Newbie

Joined: Thu Nov 22, 2007 4:31 am
Posts: 3
Hi folks,

this is what happened so far:

I have an old version of an app running and a new version which uses a different data model. All table's ids are identity columns (using sybase 15.0).

To import the old data into the new tables, I wrote an importing tool that creates two sessionFactory objects to connect to both databases.

It reads the old entities, creates entites of the new data model, puts the old data into the new entities (with some needed changes) and saves them to the new database.

This is (almost) working fine as long as I let the new entities get their ids generated automatically by sybase. By 'almost' I mean that I have to finetune the creation order of new entities in such a way that no foreign key constraints are violated. This is quite fiddly but I could invest some more time to get this working.

But unfortunately I need some of the new entities to keep the exact same id as before.

So to be able to set the new entities' ids, i removed the @generatedvalue from the new persistent classes but have the database colums still beeing identity columns. Then i tried to use an interceptor to find the right moment to set identity_insert on on the table that the entity is beeing inserted to. Doesn't work properly yet either (e.g. sybase doesnt't allow identity_insert set to ON on more than one table in one session)

To make this long story short: Before I invest even more time in getting those issues mentioned before fixed, are there other ways to achieve what I'm trying to?

I want to:
- migrate data from old to new database (different model, so stuff like bcp wont't work)
- keep id values of some of the entity classes although both new and old db use generated identity as id
- keep existing relationships between entities


Any thoughts are very welcome.

Thanks,
Klaus


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 04, 2007 11:18 am 
Newbie

Joined: Thu Nov 22, 2007 4:31 am
Posts: 3
Nobody ever did this before? I can't believe that :-(


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 14, 2007 4:08 pm 
Newbie

Joined: Fri Dec 14, 2007 4:05 pm
Posts: 2
You're quite right.. this must have been done may times before.

I am beginning work on a quick tool that does the same thing. Though, my legacy database will just be queried with raw JDBC, and then I'll use a Hibernate session to hydrate my POJOs and persist them.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 15, 2007 10:54 am 
Beginner
Beginner

Joined: Fri Jun 25, 2004 11:47 am
Posts: 34
I think you are using the wrong tool for the type of operation you want to achieve. It's probably better you have a look in direction of etl tool, i.e.:
1. search for ETL on google,
2. Example open source product: http://www.talend.com


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 15, 2007 11:05 am 
Newbie

Joined: Fri Dec 14, 2007 4:05 pm
Posts: 2
Yes and No. I agree to an extent, but it really depends on the project.

I have a relatively simple project - in fact a legacy, unnormalized database with only three tables that I need to do ETL on. Writing plain Java code (or code in a scripting language like Groovy or JRuby) is far preferable in this specific case. I tend to be a little skeptical about tools that push an IDE that goes along with them - as they usually have a pretty steep learning curve, that goes way beyond the needs of the project.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 15, 2007 9:58 pm 
Regular
Regular

Joined: Sat Nov 25, 2006 11:37 am
Posts: 72
Not being a Sybase expert but would it be possible to define the tables you want the ids preserved on first without the identity constraint on the column and then after conversion use an alter table statement to change the column type to identity?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 17, 2007 6:10 am 
Newbie

Joined: Thu Nov 22, 2007 4:31 am
Posts: 3
Thanks for your suggestions.

I have my migration tool running properly, fortunately it wasn't that much more effort. I'll have a look at some ETL tool as suggested by knoll before I have to do similar things in the future.

@malm66: I'm not aware of a possibility to alter a regular table column to be an identity column in sybase. I create a temp tables for my new data model (without identity), insert all data into them and then copy it over to the regular tables (which have identity cols) using "insert into", preceded by "SET IDENTITY_INSERT XXX ON". Here the right order matters, to avoid foreign key constraint violations.

Klaus


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