-
Notifications
You must be signed in to change notification settings - Fork 38.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@Transactional should treat UndeclaredThrowableException as a checked exception #26854
Comments
If you are proposing that be added in the Are you perhaps proposing that the |
@Sam-Kruglov, are you aware that you can configure @Transactional(noRollbackFor = UndeclaredThrowableException.class)
@SneakyThrows
public void lombokSurprise() {
jdbcTemplate.execute("insert into test_table values('lombok!')");
throw new Exception("Simple exception");
} That should help you achieve your goal. |
Editing The exception thrown is checked if it extends Exception, not if it’s declared in the method signature, so it feels like we’re checking the consequence rather than the source of truth. I think your suggestion about using cause is better, sorry, I guess I didn’t read enough of the code :) |
That's not actually a workaround but rather the supported mechanism for configuring commit/rollback semantics with declarative transaction management in Spring.
Well, we don't know why the In other words, we would not want to change the current behavior since it would indeed be breaking change.
No worries. 😉 In any case, in light of the configuration option outlined in #26854 (comment), I am closing this issue. |
Wait but we do know where it comes from: spring-framework/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java Line 767 in 01e50fb
Also, I’m aware of this configuration, still seems like a workaround to me. Thanks for your time either way! |
Even if that’s something standard in the JDK, I’m fine with wrapping it, still, feels like we should treat it as checked because this wrapper is literally for wrapping checked exceptions if I understood correctly |
I read this blogpost describing this problem:
This code is supposed to commit the transaction but it does not. The problem is that Spring wraps checked exceptions that aren't declared in the signature within an UndeclaredThrowableException over here and from that point treats it as unchecked.
I think we should treat this one as a checked exception to preserve the promised behavior. I believe it's controlled here:
spring-framework/spring-tx/src/main/java/org/springframework/transaction/interceptor/DefaultTransactionAttribute.java
Lines 171 to 188 in 01e50fb
So, we could append
|| ex instanceof UndeclaredThrowableException
to solve it.It will be a breaking change, but I think most people expect it to work that way anyway.
The text was updated successfully, but these errors were encountered: