I have a query that only fetches part of a table's values into an entity-style object. These values are being manipulated in a graphical interface.
The issue is that an update could overwrite any unused values that have been modified instead of leaving them untouched.
What is the proper way to deal with this? Should I write a method that does a partial update or simply create a new entity object for the purposes of editing?
I'm curious as well on how this is best handled. In some projects, where I could make assumptions such as "null values in the bean mean the value has not been touched", I wrote the UPDATE statement to "update" all fields, setting the column value to that of the bean if not null, else setting the column value to the pre-existing column value in the db.
UPDATE entity
SET propertyA = NVL(newPropertyA, propertyA)
,propertyB = NVL(newPropertyB, propertyB)
,propertyC = NVL(newPropertyC, propertyC)
,...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With