-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Closed
Labels
in: dataIssues in data modules (jdbc, orm, oxm, tx)Issues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancementA general enhancement
Milestone
Description
Dmitry Katsubo opened SPR-10260 and commented
In case when java.sql.DataTruncation wraps java.sql.SQLException the error code is 0. However underlying SQLException holds the error code value ("8152" in my example).
Current SQLErrorCodeSQLExceptionTranslator#doTranslate() implementation does not allow to handle this case for sqlErrorCodes.customTranslations.
- If
sqlErrorCodes.useSqlStateForTranslationis true, then custom translation bound to SQL state ("22001" in my example) will match, however other translations fromsql-error-codes.xmlwill not work. - If
sqlErrorCodes.useSqlStateForTranslationis true, then custom translation will not match, however default translations will work.
It's not possible to combine these two policies. The solution could be to loop through exception hierarchy to find first non-zero error code (code spot is highlighted in my example).
Intended XML configuration:
<bean id="exceptionTranslator" class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator">
<property name="dataSource">
<ref bean="myDaoDataSource" />
</property>
<property name="sqlErrorCodes.customTranslations">
<array>
<bean class="org.springframework.jdbc.support.CustomSQLErrorCodesTranslation">
<property name="errorCodes" value="8152" />
<property name="exceptionClass" value="org.mycompany.dao.DataTruncationException" />
</bean>
</array>
</property>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"
p:dataSource-ref="myDaoDataSource"
p:exceptionTranslator-ref="exceptionTranslator"
/>
Workarounds:
- Extend
SQLErrorCodeSQLExceptionTranslatorand overridecustomTranslate(). - Define
sqlErrorCodes.customSqlExceptionTranslator().
Affects: 3.1.2
Attachments:
- example.png (81.06 kB)
Referenced from: commits 8a4ce14
Metadata
Metadata
Assignees
Labels
in: dataIssues in data modules (jdbc, orm, oxm, tx)Issues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancementA general enhancement