-
Notifications
You must be signed in to change notification settings - Fork 41.6k
The untranslated SQLException is wrapped to UncategorizedSQLException #25493
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
Conversation
The patch solves situation when Spring Boot with jOOQ is used and database driver returns type of exception which is not translated by used SQLExceptionTranslator. In this case the last Spring Boot (2.4.3 and also 2.5.0-SNAPSHOT) throws org.jooq.exception.DataAccessException instead of expected org.springframework.dao.DataAccessException. The original SQLException is furthermore lost and getCause() returns null. The behavior was introduced with change in AbstractFallbackSQLExceptionTranslator with Spring Framework in 5.3.x. The extending translators return no longer UncategorizedSQLException but null. Null is correct return value of SQLExceptionTranslator and caller have to create UncategorizedSQLException alone like eg. JdbcTemplate does. This change fix same in JooqExceptionTranslator.
@jirkait Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
@jirkait Thank you for signing the Contributor License Agreement! |
This suggestion seems to revert spring-projects/spring-framework#24064 in the context of jOOQ, see also my comment here: spring-projects/spring-framework#24064 (comment) Is it worth reverting the behaviour only for jOOQ? I think that exception translators have changed incompatibly for good in Spring 5.3, and the jOOQ/Spring integration should be able to handle this. The resulting NPE is already fixed in jOOQ: jOOQ/jOOQ#11304 |
Thanks for the proposal, @jirkait, and for taking a look, @lukaseder. I don't think we should be reverting the changes in Spring Framework 5.3 only for jOOQ so I'm going to close this one. We've already upgraded to jOOQ 3.14.7 so we've picked up the NPE fix. |
This should be reopened. Currrently the original exception is lost in logs due to Unspecified SQLException that doesn't wrap original exception, and this requires developers to look for needles in haystacks losing time debugging to reproduce the original exception to find out what actually happened (time and money cost)... |
`JooqExceptionTranslator` needs to allow extension to allow handling of untranslated exceptions. spring-projects#25493
As described above, applying the change proposed here would make jOOQ's exception translation behave differently to all the others. That isn't something that we want to do. If you'd like to pursue this, please do so on spring-projects/spring-framework#24064 or a new Spring Framework issue so that it can be addressed consistently for all translators. |
Trying to provide more rationale about this, the way I understand it: From spring-projects/spring-framework#24064 (comment):
The translator respects Spring's contract to return
This PR doesn't change spring's translation contract (return null for untranslated), but only how the consumer handles untranslated exception: Think hypothesis: what if JOOQ suddenly decides to accept only some |
I think I know where the confusion originated from. Before spring-projects/spring-framework#24064, the translation would return The OP decided to use a behavior that matches that before 24064 and used The JOOQ So I propose the following modification:
Keep focus on the main issue here, that the original exception is lost! |
Thanks, @cdalexndr. That sounds reasonable to me. What do you think, @lukaseder? |
The type of original exception is |
In the case where translation has resulted in |
No, that's the current issue, if translation is It can be wrapped in a simple
|
Isn't it lost because we're currently passing |
@wilkinsona yeah, passing null into jooq, results in Unspecified SQLException missing the original exception. This is the current implementation. So when the exception cannot be translated (translation returns null, even tho exception is not null), we should use the original exception without translation.
Translation isn't required to pass exception to JOOQ. |
I tried the proposed change to:
The routine calling jOOQ method now throws In the meantime, I looked at the solution directly in jOOQ (like this PR [jOOQ/jOOQ#11574]), but without further investigation of the effect on jOOQ, this is not possible. I am also not sure if the fix in jOOQ is on the right place, as it probably solves the only problem in integration with spring. |
IMO, passing a |
Let's look at the call chain:
So, yes I agree, if |
Thanks, @lukaseder. I've opened #25717 to make that change. |
Hello sorry for being a little bit late to the party but as an user of Spring Boot and jOOQ I would like to point out that this behavior feels inconsistent to me. Now if I have to catch an Exception I never now what Exception to catch. My assumption was that by using the spring-boot-starter-jooq module all jOOQ Exception will be translated in some kind of org.springframework.dao.DataAccessException. This seems to be the case for most errors but now I get a org.jooq.exception.DataAccessException in some edge cases. My suggestion would be to wrap all jOOQ Exception in some kind of Spring DataAccessException or some kind of configuration to turn exception translation off completely. |
Unfortunately, this assumption doesn't hold true following the changes made in Spring Framework 5.3. We prefer to align with those changes and to allow any subsequent execute listeners to perform additional exception translation if they wish, rather than translating to something like
Getting either an
If you want to fine tune this behaviour, you can add additional exception translation of your own by configuring an If you want to disable exception translation completely, you can provide your own |
Ok thank you very much for your detailed answer. This should allow me to customize the beauvoir to my liking. |
The patch solves situation when Spring Boot with jOOQ is used and database driver returns type of exception which is not translated by used
SQLExceptionTranslator
. In this case the last Spring Boot (2.4.3 and also 2.5.0-SNAPSHOT) throwsorg.jooq.exception.DataAccessException
instead of expectedorg.springframework.dao.DataAccessException
. The originalSQLException
is furthermore lost andgetCause()
returnsnull
.The behavior was introduced with change in
AbstractFallbackSQLExceptionTranslator
with Spring Framework in 5.3.x. The extending translators return no longerUncategorizedSQLException
butnull
.null
is correct return value ofSQLExceptionTranslator
and caller have to createUncategorizedSQLException
alone like eg.JdbcTemplate
does. This change fixes same inJooqExceptionTranslator
for jOOQ.Some more details are in stack overflow question https://stackoverflow.com/questions/66279277/unexpected-mapping-of-exception-from-trigger-spring-boot-2-4-x-jooq