{"record":{"id":"7018965792eed76b","repo":"pentaho/pentaho-kettle","slug":"unexpected-error-inserting-row","errorCode":null,"errorMessage":"Unexpected error inserting row","messagePattern":"Unexpected error inserting row","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/synchronizeaftermerge/SynchronizeAfterMerge.java","lineNumber":380,"sourceCode":"            try {\n              if ( performInsert ) {\n                data.insertStatement.executeBatch();\n                data.db.commit();\n                data.insertStatement.clearBatch();\n              } else if ( performUpdate ) {\n                data.updateStatement.executeBatch();\n                data.db.commit();\n                data.updateStatement.clearBatch();\n              } else if ( performDelete ) {\n                data.deleteStatement.executeBatch();\n                data.db.commit();\n                data.deleteStatement.clearBatch();\n              }\n            } catch ( SQLException ex ) {\n              throw Database.createKettleDatabaseBatchException( BaseMessages.getString( PKG,\n                \"SynchronizeAfterMerge.Error.UpdatingBatch\" ), 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    } catch ( KettleDatabaseBatchException be ) {\n      errorMessage = be.toString();\n      batchProblem = true;\n      sendToErrorRow = true;\n      updateCounts = be.getUpdateCounts();","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/synchronizeaftermerge/SynchronizeAfterMerge.java#L362-L398","documentation":"Thrown in lookupValues() in batch mode when the batch flush block throws a non-SQLException (any other Exception). It wraps the original exception in a KettleDatabaseException with the generic message 'Unexpected error inserting row', meaning the failure was not a plain JDBC SQLException (e.g. runtime error while building/flushing the batch).","triggerScenarios":"data.batchMode is true and code in the try block around executeBatch()/commit() throws an Exception that is not a SQLException — e.g. NPE from an uninitialized statement, driver-specific unchecked exceptions.","commonSituations":"JDBC driver bugs or driver class mismatches; statements not initialized because an earlier branch skipped preparing them; OOM or driver-level runtime errors during large batches.","solutions":["Inspect the wrapped cause (getCause) of the KettleDatabaseException to identify the actual unexpected exception.","Verify the correct JDBC driver version is installed for the target database.","Toggle off batch mode to isolate whether the failure is batch-specific.","Check heap/memory availability if batches are very large; reduce batch/commit size."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"catch (KettleDatabaseException e) {\n  if (\"Unexpected error inserting row\".equals(e.getMessage())) {\n    Throwable cause = e.getCause();\n    logError(\"Non-SQL failure during batch: \" + cause);\n  }\n  throw e;\n}","preventionTips":["Use the correct, supported JDBC driver version for the database.","Monitor heap memory with large batches; reduce batch size.","Toggle batch mode off when debugging to isolate the failing operation."],"tags":["database","jdbc","batch","pentaho-kettle"],"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"}