For some reason, I was hoping that when I do a session.merge(Object), hibernate would find all the existing records that have changed and update them appropriately-- even for all relationships. However for the relationships, it seems to create new records entirely rather than updating existing records. Hence if I had a base class with a one-to-many association with a subBase class, this maps to a Base_Table and SubBase_Table respectively. When I insert a record w/ hydration of the base object, I would get something like this--
Code:
Base_Table
id | subbase_id
-------------------
1 | 1
SubBase_Table
id | text
-----------
1 | First insertion
When I change the text in the SubBase object to "Second insertion" (base.getSubBase().setText("Second insertion"); and then do a session.merge(base);, I get this behavior--
Code:
Base_Table
id | subbase_id
-------------------
1 | 2
SubBase_Table
id | text
-----------
1 | First insertion
2 | Second insertion
Is this the default behavior of merge()? I was hoping that it would just update the subbase record instead of inserting another, i.e. I would like this to happen on session.merge(base);--
Code:
Base_Table
id | subbase_id
-------------------
1 | 1
SubBase_Table
id | text
-----------
1 | Second insertion
How do I get the update-insteadof-insert behavior (if possible)?
-Larry