开发者

What is a practical process for doing data transformation on a live system when hibernate + code generation is used?

开发者 https://www.devze.com 2023-01-13 01:09 出处:网络
I have an existing database defined via HBM.XML files (code and sql dml generated via Hibernate tools), and am looking for a practical way to perform data transformation on existing data. So suppose t

I have an existing database defined via HBM.XML files (code and sql dml generated via Hibernate tools), and am looking for a practical way to perform data transformation on existing data. So suppose the following:

The original table is defined with a single FK; there is existing data. The revised table is defined with two FKs; the two FKs can be determined via the single FK using a database lookup. Integrity constraints will not be impacted by this new structure. Nothing else will be changed.

Ideally, I want the revised table to keep the original table name.

Why do I want to do this? Requirement change which force开发者_开发问答d me to undo the original normalization.

To achieve this, I am planning to do the following:

  1. Define a new mapping via HBM.XML with the revised table definition. Generate Java and database definitions.
  2. Write a module to read data from the old table and populate the new table. Run this module.
  3. Drop the old table via SQL DML; delete all generated code pertaining to the old table. Remove the HBM.XML file for the old table.
  4. Rename the revised table's HBM.XML to the old mapping's class name. Run the Java code generation ONLY. Change the revised table name in the database directly.

/end

This process is a mess, but I am unsure of how to perform these data transformations in live systems, particularly when Hibernate and code generation are involved. One of my main concerns is that bad things could happen to the index / constraints which are generated for the revised table.

If anyone can help critique my process / suggest improvements / point me to other resources, it would be most appreciated. Somewhere, sometime, someone must have done this with a production system, so I figure it's just a matter of knowing where to look.


Your process looks fine. But I would add an extra step just to make sure the transition is ok before step 1: create a database view that would represent your new schema and create .hbm/java classes to use it. Make sure the old tables are not readable in the application (through user settingss). Then deploy your application in the production environment and check the data integrity for a certain period of time. When everything looks fine, you can continue with steps 2,3,4...

0

精彩评论

暂无评论...
验证码 换一张
取 消