Partial update of object / Do not update null values with JPA

Asked

Viewed 250 times

3

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

Example, only change values that are not null ?

1 answer

1


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

  1. Load the original database object by Id using find() of the JPA Session
  2. Use a library like BeanUtils to copy the non-null properties of the updated object partially produced by the service to the object loaded by find(). See how to do here

JPA will generate the update but only the changed properties in the loaded object will have different values.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.