{"record":{"id":"3c6a020a8ad7c553","repo":"pentaho/pentaho-kettle","slug":"addsequence-exception-couldnotfindnextvalueforsequence","errorCode":null,"errorMessage":"AddSequence.Exception.CouldNotFindNextValueForSequence","messagePattern":"AddSequence\\.Exception\\.CouldNotFindNextValueForSequence","errorType":"exception","errorClass":"KettleStepException","httpStatus":null,"severity":"error","filePath":"plugins/core/impl/src/main/java/org/pentaho/di/trans/steps/addsequence/AddSequence.java","lineNumber":90,"sourceCode":"        next = data.getDb().getNextSequenceValue( data.realSchemaName, data.realSequenceName, meta.getValuename() );\n      } catch ( KettleDatabaseException dbe ) {\n        throw new KettleStepException( BaseMessages.getString(\n          PKG, \"AddSequence.Exception.ErrorReadingSequence\", data.realSequenceName ), dbe );\n      }\n    } else {\n      // This should never happen, but if it does, don't continue!!!\n      throw new KettleStepException( BaseMessages.getString( PKG, \"AddSequence.Exception.NoSpecifiedMethod\" ) );\n    }\n\n    if ( next != null ) {\n      Object[] outputRowData = inputRowData;\n      if ( inputRowData.length < inputRowMeta.size() + 1 ) {\n        outputRowData = RowDataUtil.resizeArray( inputRowData, inputRowMeta.size() + 1 );\n      }\n      outputRowData[inputRowMeta.size()] = next;\n      return outputRowData;\n    } else {\n      throw new KettleStepException( BaseMessages.getString(\n        PKG, \"AddSequence.Exception.CouldNotFindNextValueForSequence\" )\n        + meta.getValuename() );\n    }\n  }\n\n  public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {\n    meta = (AddSequenceMeta) smi;\n    data = (AddSequenceData) sdi;\n\n    Object[] r = getRow(); // Get row from input rowset & set row busy!\n    if ( r == null ) {\n      // no more input to be expected...\n      setOutputDone();\n      return false;\n    }\n\n    if ( first ) {\n      first = false;","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/core/impl/src/main/java/org/pentaho/di/trans/steps/addsequence/AddSequence.java#L72-L108","documentation":"The AddSequence step throws this KettleStepException when the selected sequence source (database sequence or counter) returned null for the next value, i.e. getNextValue() could not produce a value. The message is concatenated with meta.getValuename(), naming the output field that could not be filled. Execution of the step aborts for the current row.","triggerScenarios":"addSequence() executes, sequence method was configured, but data.realDatabaseMeta.getNextSequenceValue(...) or the counter logic returns null — e.g. the named sequence does not exist in the database, the counter exceeded its max value, or the database metadata could not be resolved at runtime.","commonSituations":"Referencing a sequence that was dropped or renamed in the target database; connecting as a user lacking SELECT on the sequence; counter-based sequence whose next value exceeds the configured maximum; wrong database connection selected in the step so the sequence lookup fails silently to null.","solutions":["Verify the sequence (or counter) exists and is accessible on the configured database connection; fix the name or create the sequence","Check the counter configuration: ensure start/increment/max values allow further values, and raise or remove the max if it was reached","Confirm the step's database connection points to the schema containing the sequence","Enable Kettle debug logging on the step to see why getNextValue() returned null before the throw"],"exampleFix":"-- before: sequence missing on target DB\nSELECT nextval('order_seq'); -- ERROR: sequence does not exist\n-- after: create the sequence the step references\nCREATE SEQUENCE order_seq START 1 INCREMENT 1;","handlingStrategy":"try-catch","validationCode":"DatabaseMeta dbm = meta.getDatabase() != null ? meta.getDatabase() : sharedDb;\nif (meta.isDatabase()) {\n  try (Connection c = dbm.getConnection()) {\n    if (!sequenceExists(c, meta.getSequenceName())) throw new IllegalStateException(\"Sequence not found: \" + meta.getSequenceName());\n  }\n}","typeGuard":"boolean sequenceResolvable(AddSequenceMeta m, DatabaseMeta dbm) {\n  return m != null && (!m.isDatabase() || (dbm != null && m.getSequenceName() != null));\n}","tryCatchPattern":"try {\n  row = addSequence(inputRow);\n} catch (KettleStepException e) {\n  if (e.getMessage().contains(\"CouldNotFindNextValueForSequence\")) {\n    logError(\"Sequence returned null for field \" + meta.getValuename() + \"; check sequence/counter config\");\n    setErrors(1); stopAll();\n  } else throw e;\n}","preventionTips":["Verify the sequence name exists and the connection user has SELECT privilege on it","For counters, set a max value that will not be reached during the run, or monitor counter exhaustion","Point the step at the correct database connection/schema for the sequence","Test the step in isolation (single row preview) before running full transformations"],"tags":["kettle","pentaho","sequence","database","null-value"],"backgroundTag":"database-query-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"}