pentaho/pentaho-kettle · error · KettleStepException

AddSequence.Exception.CouldNotFindNextValueForSequence

Error message

AddSequence.Exception.CouldNotFindNextValueForSequence

What it means

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.

Solutions

  1. Verify the sequence (or counter) exists and is accessible on the configured database connection; fix the name or create the sequence
  2. Check the counter configuration: ensure start/increment/max values allow further values, and raise or remove the max if it was reached
  3. Confirm the step's database connection points to the schema containing the sequence
  4. Enable Kettle debug logging on the step to see why getNextValue() returned null before the throw

Example fix

-- before: sequence missing on target DB
SELECT nextval('order_seq'); -- ERROR: sequence does not exist
-- after: create the sequence the step references
CREATE SEQUENCE order_seq START 1 INCREMENT 1;
Defensive patterns

Strategy: try-catch

Validate before calling

DatabaseMeta dbm = meta.getDatabase() != null ? meta.getDatabase() : sharedDb;
if (meta.isDatabase()) {
  try (Connection c = dbm.getConnection()) {
    if (!sequenceExists(c, meta.getSequenceName())) throw new IllegalStateException("Sequence not found: " + meta.getSequenceName());
  }
}

Type guard

boolean sequenceResolvable(AddSequenceMeta m, DatabaseMeta dbm) {
  return m != null && (!m.isDatabase() || (dbm != null && m.getSequenceName() != null));
}

Try / catch

try {
  row = addSequence(inputRow);
} catch (KettleStepException e) {
  if (e.getMessage().contains("CouldNotFindNextValueForSequence")) {
    logError("Sequence returned null for field " + meta.getValuename() + "; check sequence/counter config");
    setErrors(1); stopAll();
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/3c6a020a8ad7c553. Report an issue: GitHub.

Appendix: source

Thrown at plugins/core/impl/src/main/java/org/pentaho/di/trans/steps/addsequence/AddSequence.java:90

        next = data.getDb().getNextSequenceValue( data.realSchemaName, data.realSequenceName, meta.getValuename() );
      } catch ( KettleDatabaseException dbe ) {
        throw new KettleStepException( BaseMessages.getString(
          PKG, "AddSequence.Exception.ErrorReadingSequence", data.realSequenceName ), dbe );
      }
    } else {
      // This should never happen, but if it does, don't continue!!!
      throw new KettleStepException( BaseMessages.getString( PKG, "AddSequence.Exception.NoSpecifiedMethod" ) );
    }

    if ( next != null ) {
      Object[] outputRowData = inputRowData;
      if ( inputRowData.length < inputRowMeta.size() + 1 ) {
        outputRowData = RowDataUtil.resizeArray( inputRowData, inputRowMeta.size() + 1 );
      }
      outputRowData[inputRowMeta.size()] = next;
      return outputRowData;
    } else {
      throw new KettleStepException( BaseMessages.getString(
        PKG, "AddSequence.Exception.CouldNotFindNextValueForSequence" )
        + meta.getValuename() );
    }
  }

  public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {
    meta = (AddSequenceMeta) smi;
    data = (AddSequenceData) sdi;

    Object[] r = getRow(); // Get row from input rowset & set row busy!
    if ( r == null ) {
      // no more input to be expected...
      setOutputDone();
      return false;
    }

    if ( first ) {
      first = false;

View on GitHub (pinned to f3058517a1)