{"record":{"id":"bef4b86ca3f4c46c","repo":"pentaho/pentaho-kettle","slug":"unable-to-close-insert-after-populating-table-schematable","errorCode":null,"errorMessage":"Unable to close insert after populating table {schemaTable}","messagePattern":"Unable to close insert after populating table (.+?)","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/repository/kdr/KettleDatabaseRepositoryCreationHelper.java","lineNumber":379,"sourceCode":"          if ( dryrun ) {\n            sql = database.getSQLOutput( null, tablename, table, tableData, null );\n            statements.add( sql );\n          } else {\n            database.setValuesInsert( table, tableData );\n            database.insertRow();\n          }\n        }\n      }\n\n      try {\n        if ( !dryrun ) {\n          database.closeInsert();\n        }\n        if ( log.isDetailed() ) {\n          log.logDetailed( \"Populated table \" + schemaTable );\n        }\n      } catch ( KettleException dbe ) {\n        throw new KettleException( \"Unable to close insert after populating table \" + schemaTable, dbe );\n      }\n    }\n    if ( monitor != null ) {\n      monitor.worked( 1 );\n    }\n\n    // ////////////////////////////////////////////////////////////////////////////////\n    //\n    // R_NOTE\n    //\n    // Create table...\n    table = new RowMeta();\n    tablename = KettleDatabaseRepository.TABLE_R_NOTE;\n    schemaTable = databaseMeta.getQuotedSchemaTableCombination( null, tablename );\n    if ( monitor != null ) {\n      monitor.subTask( \"Checking table \" + schemaTable );\n    }\n    table.addValueMeta( new ValueMetaInteger(","sourceCodeStart":361,"sourceCodeEnd":397,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/repository/kdr/KettleDatabaseRepositoryCreationHelper.java#L361-L397","documentation":"After batch-inserting seed rows into a repository table, the helper calls database.closeInsert(); a KettleException while closing/flushing the prepared insert is wrapped as 'Unable to close insert after populating table <schemaTable>'. The rows themselves may be in limbo, so the table could be partially populated.","triggerScenarios":"createRepositorySchema() populates a lookup table (e.g. R_DATABASE_TYPE) with batch inserts, then closeInsert() throws — usually an unflushed batch error, constraint violation at flush, or connection drop.","commonSituations":"Network drop mid-batch during first-time repository creation; duplicate seed rows against an already-populated table; JDBC driver rejecting the batch on close.","solutions":["Inspect the cause for the flush/batch error; fix duplicates or constraints.","Recreate the repository schema cleanly so seeding starts from empty tables.","Verify connection stability between client and database during creation.","Re-run creation after correcting; the insert closure happens only on failures in the batch pipeline."],"exampleFix":"// before\nrepo.createRepositorySchema(monitor, false); // fails on existing seeded rows\n// after\nif (database.getRowCount(TABLE_DATABASE_TYPE) == 0) {\n  repo.createRepositorySchema(monitor, false);\n}","handlingStrategy":"validation","validationCode":"// only seed into empty tables\nif (database.getRowCount(schemaTable) == 0) {\n  performSeedInserts();\n}","typeGuard":null,"tryCatchPattern":"try {\n  repo.createRepositorySchema(monitor, false);\n} catch (KettleException e) {\n  log.error(\"seed insert close failed for \" + schemaTable + \": \" + e.getCause(), e);\n}","preventionTips":["Ensure stable network connectivity during creation.","Avoid duplicate seed rows by starting from empty tables.","Use JDBC drivers that handle batch flush reliably.","Set generous statement timeouts."],"tags":["database","batch-insert","repository-creation"],"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"}