BatchUpdateExceptionは発生しません 、 SQLErrorCodeSQLExceptionTranslator
jdbcTemplate内 、BatchUpdateExceptionを処理します ■
if (sqlEx instanceof BatchUpdateException && sqlEx.getNextException() != null) {
SQLException nestedSqlEx = sqlEx.getNextException();
if (nestedSqlEx.getErrorCode() > 0 || nestedSqlEx.getSQLState() != null) {
sqlEx = nestedSqlEx;
}
}
それについて問題があります:
SQLStateSQLExceptionTranslator
:
jdbcTemplate.setExceptionTranslator(new SQLStateSQLExceptionTranslator());
次に、BatchUpdateExceptionを取得します causeとして :
try {
// ...
} catch (DataAccessException e) {
Throwable cause = e.getCause();
logger.info("cause instanceof BatchUpdateException = {}", cause instanceof BatchUpdateException);
}
しかし postgresqljdbcドライバーの場合はBatchUpdateException#getUpdateCounts()であることに注意してください。 EXECUTE_FAILED
一部の行を正常に挿入できたにもかかわらず、のみ。
これ を参照してください 問題