I was under the impression that you should always first load an object, modify any attributes you want and then persist it even if you know the primary key id of the entity you are updating. For example, if I am updating the phone number of an employee and I know their id (primary key) is 1234, it would not be advised to do the following:
1) create a new Employee object
2) set the employee id to 1234
3) set the phone number
4) call persist on this newly constructed employee object
rather you should:
1) load the employee by id
2) set the phone number
3) persist the entity
I suppose creating a new employee, setting the id and data that changed and calling update would be similar to a detached object (or isn't it?), but is that an approach that should be avoided?
Thanks in advance!
|