HHH-15082 Abort JDBC batches on runtime exceptions as well as SQLException

This commit is contained in:
Yoann Rodière 2022-02-17 14:49:55 +01:00 committed by Sanne Grinovero
parent 73e9859fea
commit ec6cd5d0cc
3 changed files with 9 additions and 5 deletions

View File

@ -82,6 +82,10 @@ public class BatchingBatch extends AbstractBatchImpl {
LOG.debug( "SQLException escaped proxy", e );
throw sqlExceptionHelper().convert( e, "could not perform addBatch", currentStatementSql );
}
catch (RuntimeException e) {
abortBatch();
throw e;
}
statementPosition++;
if ( statementPosition >= getKey().getBatchedStatementCount() ) {
batchPosition++;

View File

@ -45,7 +45,7 @@ public class NonBatchingBatch extends AbstractBatchImpl {
abortBatch();
throw sqlExceptionHelper().convert( e, "could not execute non-batched batch statement", statementSQL );
}
catch (JDBCException e) {
catch (RuntimeException e) {
abortBatch();
throw e;
}

View File

@ -3357,7 +3357,7 @@ public abstract class AbstractEntityPersister
);
}
}
catch (SQLException | JDBCException e) {
catch (SQLException | RuntimeException e) {
if ( useBatch ) {
session.getJdbcCoordinator().abortBatch();
}
@ -3558,7 +3558,7 @@ public abstract class AbstractEntityPersister
}
}
catch (SQLException e) {
catch (SQLException | RuntimeException e) {
if ( useBatch ) {
session.getJdbcCoordinator().abortBatch();
}
@ -3684,11 +3684,11 @@ public abstract class AbstractEntityPersister
}
}
catch (SQLException sqle) {
catch (SQLException | RuntimeException e) {
if ( useBatch ) {
session.getJdbcCoordinator().abortBatch();
}
throw sqle;
throw e;
}
finally {
if ( !useBatch ) {