I’m encountering a multiple update issue in a project that uses Hibernate and Spring, where Spring Data JPA is being used with these dependencies:
Hibernate 6.6.26
Spring Boot 3.5.7
Spring Cloud 2025.0.0
Spring Cloud GCP 7.4.0
When saving an entity that has a JSON column containing a serialized object that has a numeric field, multiple updates get executed on the saved entity (resulting in the optimistic locking field ‘version’ being incremented to number 2).
The issue doesn’t arise when the numeric field isn’t present inside the serialized object saved inside JSON column, resulting in the version column having a value of 0.
Using the ‘save’ method instead of the ‘saveAndFlush’ results in just 1 update and the version column having a value of 1.
Expected behavior: no updates being performed and version number to have a value of 0.
Link to project that reproduces the issue (Docker required)
Notes on the project:
- It contains both a “working-as-expected” and a “faulty” endpoint to test. The endpoints can be called using the Postman collection file placed in the root folder
.test - When saved inside the ‘configuration’ JSON column, the serialized objects don’t contain the incriminated ‘id’ field (this is exclusion is done via Mapstruct), but removing this behavior doesn’t affect the result
- This issue was originally encountered on a project that used these dependencies:
Hibernate 6.6.26
Spring Boot 3.4.9
Spring Cloud 2024.0.2
Spring Cloud GCP 6.3.1
- The project uses a multi layer architecture like the original project, to preserve the original mapping choices made by Mapstruct that could potentially impact the issue