I have an application that is connected to an SQL database using Hibernate. When removing a person from a particular part of the application I want to reset all the information that had been set in the particular part. Below is an example of what I am on about
Stage: Bank
Fields to be set in stage:
BankName
AccNo
IBANNo
...
When removing a Person from this stage, what is the best way to reset all the information
public void resetInfo(Person person){
person.setBankName(null);
person.setAccNo(null);
person.setIBANNo(null;)
}
or
public void resetInfo(Person person){
if(person.getBankName != null) {
person.setBankName(null);
}
if(person.getAccNo != null) {
person.setAccNo(null);
}
if(person.getIBANNo != null) {
person.setIBANNo(null;)
}
}
or is there a better way to do this?
This is fine, as Hiberante internally keeps track of which all field values are changed to specify that in update query.
Also you can check this by setting
show_sql = true, to check what update query is generated by Hibernate.