implementing Spring Boot 3 and Hibernate: Transactional method not rolling back on handling
I'm working with an odd scenario with transaction management in Spring Boot 3 while using Hibernate... I have a service method annotated with `@Transactional`, but when it throws an exception, the transaction does not roll back as expected. Here's a simplified version of my service method: ```java @Service public class UserService { @Autowired private UserRepository userRepository; @Transactional public void updateUser(Long userId, UserData newUserData) { User user = userRepository.findById(userId).orElseThrow(() -> new EntityNotFoundException("User not found")); user.setName(newUserData.getName()); if (newUserData.getEmail() == null) { throw new IllegalArgumentException("Email want to be null"); } user.setEmail(newUserData.getEmail()); userRepository.save(user); } } ``` When I call this method and pass a `UserData` object with a null email, I expect the transaction to roll back, but changes are still being persisted in the database. After enabling Hibernate's SQL logging, I see that the `UPDATE` statement is executed even after the exception is thrown. I've tried adding `@Rollback` to my test method, but that doesn't seem to affect the behavior in my actual application. I also verified that the exception thrown is an unchecked exception (a subclass of `RuntimeException`), so it should trigger a rollback according to the Spring documentation. Here's how I'm calling the `updateUser` method in my controller: ```java @RestController @RequestMapping("/users") public class UserController { @Autowired private UserService userService; @PutMapping("/{id}") public ResponseEntity<Void> updateUser(@PathVariable Long id, @RequestBody UserData userData) { userService.updateUser(id, userData); return ResponseEntity.ok().build(); } } ``` I've confirmed the following configurations: - I am using Spring Boot 3.0.0 with Hibernate 5.6.8. - My `application.properties` has the following: `spring.datasource.url`, `spring.datasource.username`, and `spring.datasource.password` set correctly. - I'm not using any custom transaction managers; the default ones are being utilized. Can someone guide to understand why the transaction isn't rolling back as expected? Is there something I'm missing in the configuration or in how I'm handling exceptions? Thanks in advance! Am I missing something obvious?