{"record":{"id":"14e443ac4176079d","repo":"apache/cassandra","slug":"timestamp-must-be-set-either-on-batch-or-individua","errorCode":null,"errorMessage":"Timestamp must be set either on BATCH or individual statements: ","messagePattern":"Timestamp must be set either on BATCH or individual statements: ","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/BatchStatement.java","lineNumber":277,"sourceCode":"        if (timestampSet)\n        {\n            if (hasConditions)\n                throw new InvalidRequestException(\"Cannot provide custom timestamp for conditional BATCH\");\n\n            if (isCounter())\n                throw new InvalidRequestException(\"Cannot provide custom timestamp for counter BATCH\");\n        }\n\n        boolean hasCounters = false;\n        boolean hasNonCounters = false;\n\n        boolean hasVirtualTables = false;\n        boolean hasRegularTables = false;\n\n        for (ModificationStatement statement : statements)\n        {\n            if (timestampSet && statement.isTimestampSet())\n                throw new InvalidRequestException(\"Timestamp must be set either on BATCH or individual statements: \" + statement.source);\n\n            if (statement.isCounter())\n                hasCounters = true;\n            else\n                hasNonCounters = true;\n\n            if (statement.isVirtual())\n                hasVirtualTables = true;\n            else\n                hasRegularTables = true;\n        }\n\n        if (timestampSet && hasCounters)\n            throw new InvalidRequestException(\"Cannot provide custom timestamp for a BATCH containing counters\");\n\n        if (isCounter() && hasNonCounters)\n            throw new InvalidRequestException(\"Cannot include non-counter statement in a counter batch\");\n","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java#L259-L295","documentation":"When a batch-level USING TIMESTAMP is set, none of the individual statements may also set their own USING TIMESTAMP — the source of the write timestamp must be unambiguous. BatchStatement.validate() throws this InvalidRequestException naming the offending statement.","triggerScenarios":"BEGIN BATCH USING TIMESTAMP n containing at least one statement whose isTimestampSet() is true (statement.timestamp reported in the message), via execute or prepare.","commonSituations":"Application code that appends USING TIMESTAMP to every INSERT while a batching layer also adds a batch-level timestamp; hand-written batches converted from single-statement templates.","solutions":["Remove USING TIMESTAMP from the individual statement named in the error, keeping the batch-level timestamp","Or remove the batch-level USING TIMESTAMP and keep per-statement timestamps"],"exampleFix":"// before\nBEGIN BATCH USING TIMESTAMP 1000 INSERT INTO t (k,v) VALUES (1,'x') USING TIMESTAMP 2000; APPLY BATCH;\n// after\nBEGIN BATCH USING TIMESTAMP 1000 INSERT INTO t (k,v) VALUES (1,'x'); APPLY BATCH;","handlingStrategy":"validation","validationCode":"if (batchUsesTimestamp && statements.stream().anyMatch(ModificationStatement::isTimestampSet))\n    throw new IllegalArgumentException(\"timestamp set both on BATCH and a child statement\");","typeGuard":null,"tryCatchPattern":"try { session.execute(batch); }\ncatch (InvalidQueryException e) {\n    if (e.getMessage().startsWith(\"Timestamp must be set either on BATCH\")) { /* pick one level for the timestamp */ }\n}","preventionTips":["Choose exactly one timestamp scope per batch: batch-level OR per-statement","Have query builders assert mutual exclusivity of batch attrs and statement attrs"],"tags":["cql","batch","timestamp"],"backgroundTag":"conflicting-config-options","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}