title: how to design a DAO update method
body: <p>How do you design a DAO class for an entity that has multiple fields?</p>
  
  <p>For example for the below entity :</p>
  
  <pre><code>public class MyEntity{
  
      private long id;
      private int field1;
      private String field2;
      private Date field3;
      private Date field4;
      private int field5;
  
  }
  </code></pre>
  
  <p>Should i create a DAO class that has update methods for each field like :</p>
  
  <pre><code>public class MyEntityDao{
      public insert(MyEntity myEntity);
      public delete(MyEntity myEntity);    
      public get(long id);
      public updateField1(MyEntity myEntity)
      public updateField2(MyEntity myEntity)
      public updateField3(MyEntity myEntity)
      public updateField4(MyEntity myEntity)
      public updateField5(MyEntity myEntity)
  
  }
  </code></pre>
  
  <p>It seems like the logical thing to do but i usually see example of just a single <code>update()</code> method. In that case, how should the DAO determine which field is to be updated in the database? Does it just update all fields blindly, even though only 1 might have changed? Or should the entity class have flags as members to indicate which fields have changed?</p>