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 5fc9e3fbeb..0d43344c93 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 @@ -148,36 +148,35 @@ public abstract class AbstractBatchImpl implements Batch { @Override public final void execute() { notifyObserversExplicitExecution(); - if ( statements.isEmpty() ) { + if ( getStatements().isEmpty() ) { return; } + try { - try { - doExecuteBatch(); - } - finally { - releaseStatements(); - } + doExecuteBatch(); } finally { - statements.clear(); + releaseStatements(); } } - private void releaseStatements() { + protected void releaseStatements() { for ( PreparedStatement statement : getStatements().values() ) { - try { - statement.clearBatch(); - jdbcCoordinator.release( statement ); - } - catch ( SQLException e ) { - LOG.unableToReleaseBatchStatement(); - LOG.sqlExceptionEscapedProxy( e ); - } + clearBatch( statement ); + jdbcCoordinator.release( statement ); } getStatements().clear(); } + protected void clearBatch(PreparedStatement statement) { + try { + statement.clearBatch(); + } + catch ( SQLException e ) { + LOG.unableToReleaseBatchStatement(); + } + } + /** * Convenience method to notify registered observers of an explicit execution of this batch. */ 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 e8792ae185..2c6c5b63a8 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 @@ -71,7 +71,13 @@ public class NonBatchingBatch extends AbstractBatchImpl { throw e; } } - getStatements().clear(); + + releaseStatements(); + } + + @Override + protected void clearBatch(PreparedStatement statement) { + // no need to call PreparedStatement#clearBatch here... } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java index b3cca173b7..e6e2e50c02 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java @@ -804,9 +804,9 @@ public interface CoreMessageLogger extends BasicLogger { void splitQueries(String sourceQuery, int length); - @LogMessage(level = ERROR) - @Message(value = "SQLException escaped proxy", id = 246) - void sqlExceptionEscapedProxy(@Cause SQLException e); +// @LogMessage(level = ERROR) +// @Message(value = "SQLException escaped proxy", id = 246) +// void sqlExceptionEscapedProxy(@Cause SQLException e); @LogMessage(level = WARN) @Message(value = "SQL Error: %s, SQLState: %s", id = 247)