{"record":{"id":"7988c7f284fc22fe","repo":"pentaho/pentaho-kettle","slug":"unable-to-retrieve-value-of-auto-generated-technical-key-no","errorCode":null,"errorMessage":"Unable to retrieve value of auto-generated technical key : no value found!","messagePattern":"Unable to retrieve value of auto-generated technical key : no value found!","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/BaseDatabaseMeta.java","lineNumber":2011,"sourceCode":"  @Override\n  public boolean releaseSavepoint() {\n    return releaseSavepoint;\n  }\n\n  public Long getNextBatchIdUsingSequence( String sequenceName, String schemaName, DatabaseMeta dbm, Database ldb ) throws KettleDatabaseException {\n    return ldb.getNextSequenceValue( schemaName, sequenceName, null );\n  }\n\n  public Long getNextBatchIdUsingAutoIncSQL( String autoIncSQL, DatabaseMeta dbm, Database ldb ) throws KettleDatabaseException {\n    Long rtn = null;\n    PreparedStatement stmt = ldb.prepareSQL( autoIncSQL, true );\n    try {\n      stmt.executeUpdate();\n      RowMetaAndData rmad = ldb.getGeneratedKeys( stmt );\n      if ( rmad.getRowMeta().size() > 0 ) {\n        rtn = rmad.getRowMeta().getInteger( rmad.getData(), 0 );\n      } else {\n        throw new KettleDatabaseException( \"Unable to retrieve value of auto-generated technical key : \"\n          + \"no value found!\" );\n      }\n    } catch ( KettleValueException kve ) {\n      throw new KettleDatabaseException( kve );\n    } catch ( SQLException sqlex ) {\n      throw new KettleDatabaseException( sqlex );\n    } finally {\n      try {\n        stmt.close();\n      } catch ( SQLException ignored ) {\n        // Ignored\n      }\n    }\n    return rtn;\n  }\n\n  public Long getNextBatchIdUsingLockTables( DatabaseMeta dbm, Database ldb, String schemaName, String tableName,\n    String fieldName ) throws KettleDatabaseException {","sourceCodeStart":1993,"sourceCodeEnd":2029,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/BaseDatabaseMeta.java#L1993-L2029","documentation":"This BaseDatabaseMeta method executes an INSERT via PreparedStatement and retrieves the auto-generated key through getGeneratedKeys. If the returned generated-keys row metadata has zero fields — meaning the driver returned no key columns — it throws a KettleDatabaseException stating no auto-generated technical key value was found.","triggerScenarios":"Calling the insert-with-generated-keys API on a database/driver combination that does not return generated keys (getGeneratedKeys returns an empty result set), or the INSERT inserted nothing so no key was generated.","commonSituations":"Databases whose JDBC drivers don't support Statement.RETURN_GENERATED_KEYS (or need column-name hints); INSERT ... SELECT statements that return no keys; using the method against a table without an auto-increment/identity column.","solutions":["Confirm the target table has an identity/auto-increment primary key column.","Check the JDBC driver supports generated keys; for PostgreSQL use getGeneratedKeys with RETURNING or an appropriate driver version.","Pass the key column name(s) to prepareInsertStatement so the driver knows which generated column to return.","As a fallback, retrieve the key via a database-specific mechanism (e.g. SELECT currval, LAST_INSERT_ID()) instead of relying on generated keys."],"exampleFix":"// before\nPreparedStatement ps = connection.prepareStatement(sql); // no generated-key hint\n\n// after\nPreparedStatement ps = connection.prepareStatement(sql, new String[] { \"id\" });","handlingStrategy":"validation","validationCode":"DatabaseMetaData md = connection.getMetaData();\nif (!md.supportsGetGeneratedKeys()) {\n  // fall back to dialect-specific key retrieval instead of the generated-keys path\n}","typeGuard":null,"tryCatchPattern":"try {\n  Long key = db.getGeneratedKey(...);\n} catch (KettleDatabaseException e) {\n  LOG.warn(\"Driver returned no generated keys; falling back to SELECT currval/LAST_INSERT_ID\", e);\n}","preventionTips":["Confirm the target table has an auto-increment/identity primary key.","Verify the JDBC driver's supportsGetGeneratedKeys() returns true before using this API.","Supply the key column names when preparing the insert statement.","Prefer dialect-specific key retrieval (RETURNING, currval) when generated keys are unsupported."],"tags":["database","jdbc","generated-keys","insert"],"backgroundTag":"empty-result-set","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"}