diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/AbstractBatchImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/AbstractBatchImpl.java index bef49a41ee..c9d5714e2c 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/AbstractBatchImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/AbstractBatchImpl.java @@ -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 ); + } } /** diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/BatchingBatch.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/BatchingBatch.java index 79d7ac030e..46cd7f6c6a 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/BatchingBatch.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/BatchingBatch.java @@ -78,12 +78,12 @@ public class BatchingBatch extends AbstractBatchImpl { currentStatement.addBatch(); } catch ( SQLException e ) { - abortBatch(); + abortBatch( e ); LOG.debugf( "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; } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/NonBatchingBatch.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/NonBatchingBatch.java index 2e3f4fcff7..8385ea0384 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/NonBatchingBatch.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/NonBatchingBatch.java @@ -49,11 +49,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; } }