Reputation: 187
I am looking for some way to partially update an object without retrieving the object from DB. Say I have an Employee entity containing the following properties -
The JSON I get in the update request may not contain all the properties. I need to make sure I update only the properties provided in the request and leave all other data unchanged.
I explored some ways of achieving partial update but all of them involves retrieving the data from db. I don't have this option since the db in my case is too slow and this will increase the response time. Please suggest
Upvotes: 0
Views: 358
Reputation: 1148
You can combine @Modifying
and @Query
annotation to issue an update query
@Modifying
@Query("update Employee e set e.firstName = :firstName, e.lastName = :lastName where e.id = :id")
void updateEmployeePartially(Long id, String firstName, String lastName);
For more information, you can check this article
Upvotes: 1