Hi,
We have been using hibernate to access oracle. Since our report queries used too many joins we denormalized the table design and merged some of the table. POJO classes were not changed, only the underlying mapping files are changed. We changed some enitty to component and added more fields fields in some table by denormalizing them.
Since our POJO class didn't change, I'm using hibenate to import data from old schema and export to new schema by using two sessionfactories created with two different cfg, and hbm files representing each schema. Using database tools to do import/export is tedious since there is a drastic change in table strucure.
I have simplifed my problem below
1) POJO p = session1.load(...) // uses old schema
// POJO p uses native id gnerator
2) session2.saveOrUpdate(p) // uses new schema
Now the problem is "saveOrUpdate" uses "update" instead of "insert" since the "ID" is available in the POJO. So I changed the code to do
2a) session2.save(p) // uses new schema.
This uses "insert" but the problem is this ignores the value of "ID" in the POJO and creates a new ID.
How to fix this? I want the POJO to be saved(inserted) in the new session with the same primary key. One way is to change the *.hbm file and change the ID proerty to normal attribute, which is messy as i have many files. Is there an elegant solution to this?
Thanks for your toughts.
|