flowable/flowable-engine · error · FlowableObjectNotFoundException

Could not find a batch with id '${batchId}'.

Error message

Could not find a batch with id '${batchId}'.

What it means

DELETE /management/batches/{batchId} calls managementService.deleteBatch; if the underlying service throws FlowableObjectNotFoundException, the resource catches it and re-throws a new FlowableObjectNotFoundException typed to Batch.class with a consistent REST message. It means no batch with that id exists to delete.

Source

Thrown at modules/flowable-rest/src/main/java/org/flowable/rest/service/api/management/BatchResource.java:107

    @ApiOperation(value = "Delete a batch", tags = { "Batches" }, nickname = "deleteBatch", code = 204)
    @ApiResponses(value = {
            @ApiResponse(code = 204, message = "Indicates the batch was found and has been deleted. Response-body is intentionally empty."),
            @ApiResponse(code = 404, message = "Indicates the requested batch was not found.")
    })
    @DeleteMapping("/management/batches/{batchId}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void deleteJob(@ApiParam(name = "batchId") @PathVariable String batchId) {
        Batch batch = getBatchById(batchId);
        if (restApiInterceptor != null) {
            restApiInterceptor.deleteBatch(batch);
        }
        
        try {
            managementService.deleteBatch(batchId);
        } catch (FlowableObjectNotFoundException aonfe) {
            // Re-throw to have consistent error-messaging across REST-api
            throw new FlowableObjectNotFoundException("Could not find a batch with id '" + batchId + "'.", Batch.class);
        }
    }
}

View on GitHub (pinned to d6d39ce1c6)

Solutions

  1. Check existence first with managementService.createBatchQuery().batchId(batchId).singleResult() and skip the delete when null.
  2. Treat the 404 as idempotent success in the client (delete-then-ignore-not-found).
  3. Verify the id is a batch id and points to the intended database/environment.
  4. If batches vanish quickly, disable/adjust automatic batch cleanup or query before acting.

Example fix

// before
Batch b = managementService.createBatchQuery().batchId(id).singleResult();
deleteBatchUnchecked(id); // 404 on second call
// after
Batch b = managementService.createBatchQuery().batchId(id).singleResult();
if (b != null) { managementService.deleteBatch(id); } // idempotent
Defensive patterns

Strategy: validation

Validate before calling

Batch batch = managementService.createBatchQuery().batchId(batchId).singleResult();
if (batch != null) { managementService.deleteBatch(batchId); }

Try / catch

try { client.deleteBatch(batchId); }
catch (FlowableObjectNotFoundException e) { /* already deleted — treat as success for idempotent delete */ }

Prevention

When it happens

Trigger: DELETE /management/batches/{batchId} with an unknown, already-deleted, or already-completed-and-purged batch id.

Common situations: Double-delete (retry after the first delete succeeded); batch finished and removed by cleanup between listing and deleting; stale id cached from a previous run or another database.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11). Data as JSON: /api/errors/272af315d967c6b5. Report an issue: GitHub.