I'm using JPA for a webservice, and I'm using
Merge for updating, but it updates all the values of my object, is there any way to do a partial update of it?
Example, only change values that are not null ?
merge operation will always synchronize all object state in the database. But there is a way to accomplish what you want:
- Load the original object from the database by
find()from the JPA session
- Use a library like
BeanUtilsto copy the non-null properties of the updated object partially produced by the service to the object loaded by
find(). See how to do it here
JPA will generate the update but only the properties changed in the loaded object will have different values.