Partial object update / Do not update null values with JPA

3

I'm using JPA for a webservice, and I'm using Merge to update, but it updates all my object values, is there any way to perform a partial update of it?

Example, only change values that are not null?

    
asked by anonymous 08.09.2017 / 15:34

1 answer

1

The merge operation of JPA will always synchronize the entire state of the object in the database. But there is a way to accomplish what you want:

  • Load the original database object by Id using find() of JPA session
  • Use a library as BeanUtils to copy the non-null properties of the partially updated object produced by the service to the object loaded by find() . Here's how to here / a>
  • JPA will generate the update but only the properties changed in the loaded object will have different values.

        
    08.09.2017 / 17:29