You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Starting with Spring Boot 3.4 (which brings Hibernate 6.6.x), manually assigning an ID to an entity annotated with @GeneratedValue causes a runtime exception (ObjectOptimisticLockingFailureException), whereas in Spring Boot 3.3.2 (Hibernate 6.5.x), the same code executes without error — Hibernate would simply ignore the manually set ID.
This appears to be a regression or at least a behavioral change that may impact existing test code and data seeding scripts.
Sample Code to Reproduce
@EntitypublicclassEmployee {
@Id@GeneratedValue(strategy = GenerationType.IDENTITY)
privateLongid;
privateStringname;
privateStringemail;
privateLongsalary;
}
// In test or data setupEmployeeemployee = Employee.builder()
.id(1L) // Manually setting ID
.name("Test")
.email("test@example.com")
.salary(100L)
.build();
employeeRepository.save(employee);
Behavior
✅ Expected (Spring Boot 3.3.x / Hibernate 6.5.x)
Manually set ID is ignored.
Entity is saved with generated ID without any exception.
❌ Actual (Spring Boot 3.4.x / Hibernate 6.6.x)
Exception is thrown:
org.springframework.orm.ObjectOptimisticLockingFailureException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.app.testing.entities.Employee#1]
Environment
Spring Boot: 3.4.x
spring-data-jpa: latest (as managed by Spring Boot 3.4)
Hibernate: 6.6.x
JDK: 21
Question
Is this change in behavior intentional due to Hibernate upgrade?
If so, could it be noted in release notes or migration guide?
Or is this a candidate for backward-compatible support or configuration toggle?
Thanks for your time!
The text was updated successfully, but these errors were encountered:
Description
Starting with Spring Boot 3.4 (which brings Hibernate 6.6.x), manually assigning an ID to an entity annotated with
@GeneratedValue
causes a runtime exception (ObjectOptimisticLockingFailureException
), whereas in Spring Boot 3.3.2 (Hibernate 6.5.x), the same code executes without error — Hibernate would simply ignore the manually set ID.This appears to be a regression or at least a behavioral change that may impact existing test code and data seeding scripts.
Sample Code to Reproduce
Behavior
✅ Expected (Spring Boot 3.3.x / Hibernate 6.5.x)
Manually set ID is ignored.
Entity is saved with generated ID without any exception.
❌ Actual (Spring Boot 3.4.x / Hibernate 6.6.x)
Exception is thrown:
Environment
Question
Is this change in behavior intentional due to Hibernate upgrade?
If so, could it be noted in release notes or migration guide?
Or is this a candidate for backward-compatible support or configuration toggle?
Thanks for your time!
The text was updated successfully, but these errors were encountered: