I tried searching this over the net but in vain. Is there a way to use hibernate to perform an idempotent update.
One use case is to use HTTP PUT to update a specific f
In hibernate if you get an object and try to modify one of it`s property and commit the transaction. Hibernate compares new values to the old values. Issues an UPDATE for all persistent properties of the entity only if the new value of at least one of the property is different than the old value.
Example:
EntityA a = hibernateSession.find(EntityA.class, id);
a.setPhone(newPhoneValue);
hibernateSession.flush().
Hibernate compares new values to the old values. Issues an UPDATE for all persistent properties of x if the old and the new value of propertyB are different.Issue an update like : UPDATE entityA set phone=?, name=?, updateDate=? WHERE id=?
If you want you can use dynamic-update and dynamic-insert in the mapping.
dynamic-update (optional - defaults to false): specifies that UPDATE SQL should be generated at runtime and can contain only those columns whose values have changed.
dynamic-insert (optional - defaults to false): specifies that INSERT SQL should be generated at runtime and contain only the columns whose values are not null.
With dynamic-update set to true hibernate will issue a UPDATE
without the name
column because it has not change.
UPDATE entityA set phone=?, updateDate=? WHERE id=?