NimChimpsky
NimChimpsky

Reputation: 47290

Using Hibernate to migrate data

Developing a brand new schema/app which uses hibernate to create tables from pojo's.

My desire is to now migrate existing data from legacy db to new schema, which is a matter of creating approriate sql and populating my new pojo's.

Secondly, it is intended that this app will be used by others, migrating from different db schema's. My initial thinkign is to therefore put the relevant sql into xml files so they can be easily changed without altering the java.

For example my current system will select loginname from logintable into pojo : User.setUsername() and then do a hibernate save. And then I can simply change the sql at a later date makign sure it returns the correct data.

Does this sound sensible ? Is their existing functionality in hibernate for doing migrations/bulk inserts ? Or will I simply be calling this n times :

User user = new User();
session.save(user);

Upvotes: 3

Views: 2740

Answers (1)

ManuPK
ManuPK

Reputation: 11829

Few thoughts here.

schema/app which uses hibernate to create tables from pojo's.

It is not a good practice to use the hibernate to generate the table. There should be separate scripts created for that. Basically hbm2ddl.auto=create setting in hibernate is a temporary way to create the tables, but you should not be using it in a standard application. It is even unsafe to have this entry in your configuration settings.Read here for more.

Schema migration/ data migration

There are lots of database available that will help you to migrate bot the schema and the data and hibernate in not really meant for this. I am not aware of those but I have seen my DB Admins doing it with ease. You might achieve it using some tricks but it is better to refrain from that.

Upvotes: 2

Related Questions