Skip to content

SQLExceptionTranslators do not reliably translate QueryTimeoutException [SPR-11959] #16575

@spring-projects-issues

Description

@spring-projects-issues

Francisco Lozano opened SPR-11959 and commented

With SQLErrorCodeSQLExceptionTranslator, my code can catch both DuplicateKeyException and DataIntegrityViolationException. This helps to distinguish between a FK constraint violation and a duplicate key, directly and without having to dig more onto the database to find out.

I had to change my use of JdbcTemplate to force SQLExceptionSubclassTranslator, in order to gracefully handle query timeouts. Unfortunately, this had the effect of rendering all my catches of DuplicateKeyException unreachable.

So, by default and without coding anything, as a user of Spring JDBC wrappers I'm stuck between a rock and a hard place.

I guess the workaround is to make a custom SQLExceptionTranslator, but this use-case is not so strange and it would be great if Spring could come with a "smart" SQL exception translator that uses whatever it needs to provide the most accurate exception possible.

I'm not sure now this should be reported a "bug" or as something else... I initially considered SQLErrorCodeSQLExceptionTranslator "buggy" because it is not translating exceptions onto DuplicateKeyException, but I can see in this case it's not straightforward to do it right for everyone.


Affects: 4.0.5

Issue Links:

Referenced from: commits 4082274

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions