-
Notifications
You must be signed in to change notification settings - Fork 38.1k
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
Revisit DataAccessException translation API #24634
Comments
Apply sorting on detected PersistenceExceptionTranslators. Relates to spring-projects#24634
I intend to revisit this for 6.1, in the context of some of the 6.0 baseline upgrades that we did, e.g. |
Also, as of #24644, |
|
I am implementing transaction retry mechanism to our applications and using
DataAccessException
mapping facility to translate some db failures to transient exception.Since
DataAccessException
mapping is one of the early days feature of spring-framework, I felt some of the APIs are bit outdated.Here is list of things I encountered:
SQLErrorCodeSQLExceptionTranslator
requires subclassing to perform custom mapping logic.To add custom mappings to existing logic,
SQLErrorCodeSQLExceptionTranslator#customTranslate
need to be overridden by subclass.I made a delegation subclass, then injected custom translators.
I think composition style API is nicer to have than sub-classing.
Does not have a way to append/update some of the error codes on
SQLErrorCodes
(not just entire override)Error code provided by
org/springframework/jdbc/support/sql-error-codes.xml
(SQL_ERROR_CODE_DEFAULT_PATH
) can be overridden bysql-error-codes.xml
(SQL_ERROR_CODE_OVERRIDE_PATH
).However, the override is done by bean(DB type). So, it cannot partially update error codes on a specific bean. For example, adding some error codes to transient exceptions to PostgreSQL.
To workaround repeating entire DB error code mapping, I created a
SQLErrorCodesUpdater
which uses the nature that theSQLErrorCodes
is a mutable java bean.Then, run them at runtime
Alternatively,
CustomSQLErrorCodesTranslation
can be used to provide custom mappings, but it is mapped toSQLErrorCodes
instance which is database vendor specific. I can create a custom error code map, but assigning it requires to retrieve db vendor type.Still it's a bit complicated to just apply custom error code mappings.
SQLErrorCodes
does not know the db vendor name, I need to retrieve it from datasource. (SQLErrorCodes#getDatabaseProductName()
returns one from bean property and different from bean id(db vendor name), which is a bit confusing as well.)An instance of
SQLErrorCodeSQLExceptionTranslator
is specific to single DB typeSQLErrorCodeSQLExceptionTranslator when
setDataSource
,setDatabaseProductName
,setSqlErrorCodes
, or corresponding constructors are called, thensqlErrorCodes
is populated for the specific DB vendor type.This makes the bean dependent to specific vendor type. It is fine but not simple to find this dependency until digging the code.
Probably adding documentation would be helpful.
PersistenceExceptionTranslationInterceptor#detectPersistenceExceptionTranslators
does not consider orderingWhen multiple
PersistenceExceptionTranslator
are available, there is no way to specify ordering.I don't find any workaround to guarantee the ordering of each translator unless spring code is updated to consider the ordering.
The text was updated successfully, but these errors were encountered: