HHH-15082 Correctly propagate the original exception when aborting a JDBC batch fails

Not strictly necessary, but it's related to these changes
and I think it's a good idea.
This commit is contained in:
Yoann Rodière 2022-02-17 14:52:40 +01:00 committed by Sanne Grinovero
parent 14c8fb752d
commit cf9d131d35
3 changed files with 13 additions and 8 deletions

View File

@ -93,8 +93,13 @@ public abstract class AbstractBatchImpl implements Batch {
return sqlStatementLogger;
}
protected void abortBatch() {
jdbcCoordinator.abortBatch();
protected void abortBatch(Exception cause) {
try {
jdbcCoordinator.abortBatch();
}
catch (RuntimeException e) {
cause.addSuppressed( e );
}
}
/**

View File

@ -78,12 +78,12 @@ public class BatchingBatch extends AbstractBatchImpl {
currentStatement.addBatch();
}
catch ( SQLException e ) {
abortBatch();
abortBatch( e );
LOG.debug( "SQLException escaped proxy", e );
throw sqlExceptionHelper().convert( e, "could not perform addBatch", currentStatementSql );
}
catch (RuntimeException e) {
abortBatch();
abortBatch( e );
throw e;
}
statementPosition++;
@ -130,12 +130,12 @@ public class BatchingBatch extends AbstractBatchImpl {
checkRowCounts( rowCounts, statement, sql );
}
catch ( SQLException e ) {
abortBatch();
abortBatch( e );
LOG.unableToExecuteBatch( e, sql );
throw sqlExceptionHelper().convert( e, "could not execute batch", sql );
}
catch ( RuntimeException re ) {
abortBatch();
abortBatch( re );
LOG.unableToExecuteBatch( re, sql );
throw re;
}

View File

@ -42,11 +42,11 @@ public class NonBatchingBatch extends AbstractBatchImpl {
jdbcCoordinator.afterStatementExecution();
}
catch ( SQLException e ) {
abortBatch();
abortBatch( e );
throw sqlExceptionHelper().convert( e, "could not execute non-batched batch statement", statementSQL );
}
catch (RuntimeException e) {
abortBatch();
abortBatch( e );
throw e;
}
}