Hi,
I am trying to syncronize data from one database to another using Hibernate.
Hibernate version: hibernate-3.2
Name of the database I am using: MS SQL Server 2005
My tables use generated identifiers as primary keys.
I use the name of an object as its natural id. For example,
Database 1 has table customer with one row having values cust_id=100, cust_name="ABC" and cust_address="XYZ"
Database 2 has table customer with one row having values cust_id=500, cust_name="ABC" and cust_address="XYZ"
Both these rows represent the same information since they have the same cust_name "ABC". Now if cust_address is updated in DB1 from "XYZ" to "XYZ1", I want it to get syncronized with DB2 at some point later. I used hibernate to reverse engineer my DB schema and I got my mapping files and some POJO's. I query the data in DB1, with lazy loading set to false. Therefore, all data corrosponding to child objects gets populated in my POJO.
I then detach the hibernate object and send it over the network as a XML stream. On the other side, I deserialize the XML and get the hibernate POJO back as it was. Now the POJO contains other objects as members forming an object graph. I am assuming that I can now save this object to the database using saveOrUpdate. However, the POJO I have contains identifiers for the contained objects and I get errors when I try to perform the save. Is it possible to indicate to hibernate to ignore the id feilds populated in my POJO ? Can I somehow save my POJO that I transferred over the wire to my new database ?
Let me know in case you need more information.
Thanks,
Amol
|