-
Notifications
You must be signed in to change notification settings - Fork 38.5k
DataSourceTransactionManager does not consider SQLExceptionTranslator on commit #24064
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
Comments
So we could introduce a configurable |
@jhoeller Thank you for your insightful feedback. I did not really realize that the translation manager is actually not used for commit-level exceptions. Your suggestion makes perfect sense. Thanks for adding it to the 5.3 roadmap! |
I'm introducing a separate As a part of this change, our default |
I wonder if there could have been another solution that didn't involve breaking the contract on the
This Line 68 in e9cded5
|
Disclaimer: I understand that questions should be asked on SO, but I believe the following is rather a bug report than a question. It has also been asked on https://stackoverflow.com/questions/59006479/how-to-properly-retry-a-serializable-transaction-with-spring.
I am developing against a PostgreSQL v12 database. I am using
SERIALIZABLE
transactions. The general idea is that when PostgreSQL detects a serialization anomaly, one should retry the complete transaction.I am using Spring's
AbstractFallbackSQLExceptionTranslator
to translate database exceptions to Spring's exception classes. This exception translator should translate the PostgreSQL error40001
/serialization_failure
to aConcurrencyFailureException
. Spring JDBC maintains a mapping file to map the PostgreSQL-specific code40001
to a genericcannotSerializeTransactionCodes
class of database exceptions, which translates into aConcurrencyFailureException
for the API user.My idea was to rely on the Spring Retry project to retry a
SERIALIZABLE
transaction which is halted due to a serialization error as following:In service implementation, I would simply replace
@Transactional
by@SerializableTransactionRetry
and be done with it.Now, back to PostgreSQL. Essentially, there are two stages at which a serialization anomaly can be detected:
It seems that Spring's
AbstractFallbackSQLExceptionTranslator
is properly translating a serialization anomaly which is detected during the execution of a statement, but fails to translate one during the commit phase. Consider the following stack trace:As you can see, PostgreSQL detects a serialization anomaly (
ERROR: could not serialize access due to ...
), but this is translated by Spring into aTransactionSystemException
instead of aConcurrencyFailureException
.I could alter the
SerializableTransactionRetry
annotation above to include aTransactionSystemException
as well, but I believe that would be wrong, as now we will be retrying upon any kind of transaction error, which is not what we want here.Is this a shortcoming in Spring's
AbstractFallbackSQLExceptionTranslator
? I am using Spring 5.2.1.The text was updated successfully, but these errors were encountered: