{"record":{"id":"2c7d3f119a9d4f7c","repo":"pentaho/pentaho-kettle","slug":"error-updating-batch","errorCode":null,"errorMessage":"Error updating batch","messagePattern":"Error updating batch","errorType":"exception","errorClass":"KettleDatabaseBatchException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/tableoutput/TableOutput.java","lineNumber":293,"sourceCode":"      // Release the savepoint if needed\n      //\n      if ( data.useSafePoints ) {\n        if ( data.releaseSavepoint ) {\n          data.db.releaseSavepoint( data.savepoint );\n        }\n      }\n\n      // Perform a commit if needed\n      //\n\n      if ( ( data.commitSize > 0 ) && ( ( commitCounter % data.commitSize ) == 0 ) ) {\n        if ( data.db.getUseBatchInsert( data.batchMode ) ) {\n          try {\n            insertStatement.executeBatch();\n            data.db.commit();\n            insertStatement.clearBatch();\n          } catch ( SQLException ex ) {\n            throw Database.createKettleDatabaseBatchException( \"Error updating batch\", ex );\n          } catch ( Exception ex ) {\n            throw new KettleDatabaseException( \"Unexpected error inserting row\", ex );\n          }\n        } else {\n          // insertRow normal commit\n          data.db.commit();\n        }\n        // Clear the batch/commit counter...\n        //\n        data.commitCounterMap.put( tableName, Integer.valueOf( 0 ) );\n        rowIsSafe = true;\n      } else {\n        rowIsSafe = false;\n      }\n\n      // See if we need to get back the keys as well...\n      if ( meta.isReturningGeneratedKeys() ) {\n        RowMetaAndData extraKeys = data.db.getGeneratedKeys( insertStatement );","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/tableoutput/TableOutput.java#L275-L311","documentation":"When batch mode is enabled, the accumulated JDBC batch of INSERT statements is flushed with PreparedStatement.executeBatch(); a SQLException there is wrapped via Database.createKettleDatabaseBatchException into a 'Error updating batch' exception. It indicates one or more statements in the batch failed at the database.","triggerScenarios":"insertStatement.executeBatch() or data.db.commit() throws SQLException while flushing a batch in writeToTable with data.batchMode active (commit size > 1 and driver supports batch).","commonSituations":"Constraint violations (PK/unique/FK) on some rows in the batch; data truncation for oversized values; connection dropped mid-batch; deadlock; driver not supporting true batching.","solutions":["Inspect the wrapped KettleDatabaseBatchException's exceptions list to identify the offending rows and fix the data (duplicates, bad values).","Disable 'Use batch update' in the step, or reduce commit size, to isolate single-row errors.","Verify table constraints and column sizes match the data being inserted.","Check DB connectivity/network stability if failures are intermittent."],"exampleFix":"// before: batch mode on with duplicate PKs in the stream\n// after: deduplicate upstream (e.g. 'Unique rows' step) or disable batch update in TableOutput dialog","handlingStrategy":"try-catch","validationCode":"// Pre-flight: check for duplicate keys / constraint breakers before insert\nSet<String> seen = new HashSet<>();\nfor ( Object[] row : rows ) {\n  String key = buildKey( row );\n  if ( !seen.add( key ) ) throw new IllegalArgumentException( \"Duplicate key in batch: \" + key );\n}","typeGuard":null,"tryCatchPattern":"try {\n  insertStatement.executeBatch();\n  data.db.commit();\n} catch ( KettleDatabaseBatchException be ) {\n  logFailedRows( be.getExceptionsList() );\n  data.db.rollback();\n  // retry rows individually with batch mode off\n}","preventionTips":["Deduplicate and validate data before TableOutput when using batch mode","Match column sizes/types to table schema to avoid truncation errors","Start with a small commit size and increase once data quality is proven","Monitor connection stability for long-running batch loads"],"tags":["kettle","table-output","jdbc","batch","database"],"backgroundTag":"database-write-failed","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}