What should be the DAO design strategy for the upgrade operation?

I myself am surprised that this question never came to me, but this time I am worried, as I am creating my own application.

I have a TaskDetail class that has 30 fields. when updating there can be only a small part of the TaskDetail, which can be updated as soon as the "endDate" of the task. We can use two strategies to update this field.

  • APPROACH 1: update the entire object with all 30 fields, and let the remaining fields be overwritten in the database with the same value, we expect a changed field that will be updated with the new value. OR
  • APPROACH 2: Update only the field that has been changed. In this case, we will consider Employee as a DTO and simply fill the "endDate" field with a new value, because it is the only field that needs to be changed.

Both approaches seem to have their pros and cons

APPROACH 1: (ORIGIN) - its cleaner approach. (CONS). We unnecessarily rewrite 29 additional fields for one field.

APPROACH 2: (PROS) - We just update the fields that are changed (CONS) - makes the DAO dirty, because we need 30 zero checks to determine which field needs to be updated.

This problem makes me a little uncomfortable.

Which of these approaches is acceptable or is there a third approach? I do not really like to use hibernation, although I prefer the Spring JDBC template.

+3
1

. 1 , 29 . , , . , , DAO , .

+1

All Articles