I am myself surprised that this question never occurred to me before but this time i am bothered since i am creating my own application.
I have a TaskDetail class that has 30 fields. while updating there could be only a small part of TaskDetail that may be updated like just the "endDate" of the task. We can use two strategies to update this field.
APPROACH 1 : Update entire object with all the 30 fields and let the rest fields be overwritten in the database with the same value expect the changed field which will be updated with new value.
OR
APPROACH 2 : Update just the field that has been changed. In this case we would treat Employee as a DTO and just populate the "endDate" field with new value since it is the only field that needs to be changed.
Both the approaches seem to have its pros and cons
APPROACH 1 : (PROS) - Its a cleaner approach. (CONS) - We are unnecessarily over-writing 29 additional field for the sake of one field.
APPROACH 2 : (PROS) - We are just updating the fields that are modified (CONS) - Makes the DAO dirty looking because we would need 30 null checks to identify which of field have to be updated.
This problem is making me a little uncomfortable.
Which of this approach is an accepted one or there is a third approach? I am not very much in favor of using hibernate although prefer Spring
JDBC template.