We are migrating a Spring Boot application from version 2.7 to version 3.3, along with an Open Liberty server and an Oracle 19 database.
Our services have a
@Transactional(readOnly = true)
annotation at the class level.
After upgrading to Spring Boot 3.3, we encountered the following issue. When we call, for example, a simple find method from our service, we get the error:
org.springframework.transaction.UnexpectedRollbackException: JTA transaction unexpectedly rolled back (maybe due to a timeout)
We have found that this error occurs when we throw a business exception of type RuntimeException, which is handled in the service layer. This exception causes the aforementioned error (UnexpectedRollbackException) to occur, as a RuntimeException leads to a rollback.
On the old system, this error does not occur. That’s why we looked further into it. On the old system, Spring automatically uses the WebSphereUowTransactionManager. On the new system, Spring uses the JpaTransactionManager.
Our hypothesis is that the WebSphereUowTransactionManager and JpaTransactionManager behave differently. It appears that the WebSphereUowTransactionManager does not cause an UnexpectedRollbackException with a @Transactional(readOnly = true) annotation.
We have tried to set up the WebSphereUowTransactionManager under Spring Boot 3.3, but we have not been successful, as this has been removed from spring-tx 6.
Alternative:
If we change our @Transactional(readOnly = true) annotation to @Transactional(readOnly = true, noRollbackFor = CustomApplicationException.class), everything seems to work fine so far.
Question 1:
How can we use the WebSphereUowTransactionManager under Spring Boot 3.3?
Question 2:
Is the alternative a viable solution to bypass the issue? Do you foresee any problems with this approach?
Mark is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.