How do you design a DAO class for an entity that has multiple fields?
For example for the below entity :
public class MyEntity{
private long id;
private int field1;
private String field2;
private Date field3;
private Date field4;
private int field5;
}
Should i create a DAO class that has update methods for each field like :
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)
}
It seems like the logical thing to do but i usually see example of just a single update()
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?