HHH-13050 - On release of batch it still contained JDBC statements logged

(cherry picked from commit 11e71f6977)
This commit is contained in:
Andrea Boriero 2018-11-06 14:28:30 -05:00 committed by Gail Badner
parent 1642853c89
commit fdab459b82
3 changed files with 14 additions and 5 deletions

View File

@ -40,8 +40,8 @@ public abstract class AbstractBatchImpl implements Batch {
private final SqlStatementLogger sqlStatementLogger;
private final SqlExceptionHelper sqlExceptionHelper;
private LinkedHashMap<String,PreparedStatement> statements = new LinkedHashMap<String,PreparedStatement>();
private LinkedHashSet<BatchObserver> observers = new LinkedHashSet<BatchObserver>();
private LinkedHashMap<String, PreparedStatement> statements = new LinkedHashMap<>();
private LinkedHashSet<BatchObserver> observers = new LinkedHashSet<>();
protected AbstractBatchImpl(BatchKey key, JdbcCoordinator jdbcCoordinator) {
if ( key == null ) {
@ -162,7 +162,15 @@ public abstract class AbstractBatchImpl implements Batch {
protected void clearBatch(PreparedStatement statement) {
try {
statement.clearBatch();
// This code can be called after the connection is released
// and the statement is closed. If the statement is closed,
// then SQLException will be thrown when PreparedStatement#clearBatch
// is called.
// Ensure the statement is not closed before
// calling PreparedStatement#clearBatch.
if ( !statement.isClosed() ) {
statement.clearBatch();
}
}
catch ( SQLException e ) {
LOG.unableToReleaseBatchStatement();

View File

@ -77,6 +77,7 @@ public class BatchingBatch extends AbstractBatchImpl {
currentStatement.addBatch();
}
catch ( SQLException e ) {
abortBatch();
LOG.debugf( "SQLException escaped proxy", e );
throw sqlExceptionHelper().convert( e, "could not perform addBatch", currentStatementSql );
}

View File

@ -29,6 +29,7 @@ import org.hibernate.AssertionFailure;
import org.hibernate.EntityMode;
import org.hibernate.FetchMode;
import org.hibernate.HibernateException;
import org.hibernate.JDBCException;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.MappingException;
@ -3171,9 +3172,8 @@ public abstract class AbstractEntityPersister
.executeUpdate( insert ), insert, -1
);
}
}
catch (SQLException e) {
catch (SQLException | JDBCException e) {
if ( useBatch ) {
session.getJdbcCoordinator().abortBatch();
}