Skip to content

Commit 4a898c5

Browse files
committed
HHH-7689 - Error executing batch should abort rest of batch for "cleanliness" sake
1 parent 0e164d1 commit 4a898c5

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/AbstractBatchImpl.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -148,36 +148,35 @@ private PreparedStatement buildBatchStatement(String sql, boolean callable) {
148148
@Override
149149
public final void execute() {
150150
notifyObserversExplicitExecution();
151-
if ( statements.isEmpty() ) {
151+
if ( getStatements().isEmpty() ) {
152152
return;
153153
}
154+
154155
try {
155-
try {
156-
doExecuteBatch();
157-
}
158-
finally {
159-
releaseStatements();
160-
}
156+
doExecuteBatch();
161157
}
162158
finally {
163-
statements.clear();
159+
releaseStatements();
164160
}
165161
}
166162

167-
private void releaseStatements() {
163+
protected void releaseStatements() {
168164
for ( PreparedStatement statement : getStatements().values() ) {
169-
try {
170-
statement.clearBatch();
171-
jdbcCoordinator.release( statement );
172-
}
173-
catch ( SQLException e ) {
174-
LOG.unableToReleaseBatchStatement();
175-
LOG.sqlExceptionEscapedProxy( e );
176-
}
165+
clearBatch( statement );
166+
jdbcCoordinator.release( statement );
177167
}
178168
getStatements().clear();
179169
}
180170

171+
protected void clearBatch(PreparedStatement statement) {
172+
try {
173+
statement.clearBatch();
174+
}
175+
catch ( SQLException e ) {
176+
LOG.unableToReleaseBatchStatement();
177+
}
178+
}
179+
181180
/**
182181
* Convenience method to notify registered observers of an explicit execution of this batch.
183182
*/

hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/NonBatchingBatch.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,13 @@ public void addToBatch() {
7171
throw e;
7272
}
7373
}
74-
getStatements().clear();
74+
75+
releaseStatements();
76+
}
77+
78+
@Override
79+
protected void clearBatch(PreparedStatement statement) {
80+
// no need to call PreparedStatement#clearBatch here...
7581
}
7682

7783
@Override

hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,9 +804,9 @@ void settersOfLazyClassesCannotBeFinal(String entityName,
804804
void splitQueries(String sourceQuery,
805805
int length);
806806

807-
@LogMessage(level = ERROR)
808-
@Message(value = "SQLException escaped proxy", id = 246)
809-
void sqlExceptionEscapedProxy(@Cause SQLException e);
807+
// @LogMessage(level = ERROR)
808+
// @Message(value = "SQLException escaped proxy", id = 246)
809+
// void sqlExceptionEscapedProxy(@Cause SQLException e);
810810

811811
@LogMessage(level = WARN)
812812
@Message(value = "SQL Error: %s, SQLState: %s", id = 247)

0 commit comments

Comments
 (0)