After more research and debugging and trial & error, it turns out the solution is very simple. The value of the version
field of the entity being persisted must match what is currently in the DB. If the values don't match Hibernate presumes that something else updated the DB and consequently throws the org.hibernate.StaleObjectStateException
.
Ensuring that the JSON being submitted has a matching PK and version value as the row in the DB, then the repo.save(user)
will update the existing row. If the version field is null, the entity is persisted as a new row.