Copy and Merge
amehta5Mar 15 2010 — edited Mar 16 2010We use Toplink 10.1.3 and have the following mappings:
Customer has a one-to-many relationship with Vehicles; and Vehicles has a 1-to-1 back-reference for the Customer.
In our use case we are trying to update 2 directly mapped attributes in the vehicle
Our code is like this -
Loop through a list of vehicles PKs-
FindObject (vehicle by Primary Key)
Session.copyObject(object, copyPolicy.cascadeAllParts)
vehicleCopy.setAttribute1
vehicleCopy.setAttribute2
vehicleUpdateList.add(vehicleCopy)
End loop
begin transaction
loop through the update list
uow.deepMergeClone(pcObject);
end loop
commit transaction
What we are finding is that the only the last record gets updated.
If customer1 owns more than one vehicle and more than one of the customer's vehicles are being updated then only the last vehicle is updated.
I ran it in debug mode and see that when the merger is run on the first vehicle it has its new values but when the merge is executed on the next vehicle the previous vehicle's attributes are set back to its original value and hence only the last vehicle gets updated.
I can't figure out why the changes are being ignored and hope someone can point out what is wrong.
Can someone shed a light on how the copy and merge work and also the best practices on it.
Thanks, appreciate the feedback