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
- Check existence first with managementService.createBatchQuery().batchId(batchId).singleResult() and skip the delete when null.
- Treat the 404 as idempotent success in the client (delete-then-ignore-not-found).
- Verify the id is a batch id and points to the intended database/environment.
- 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
- Make deletes idempotent: ignore not-found on retry.
- Don't cache batch ids across environments/databases.
- Query the batch before deleting when the flow may race with cleanup.
- Confirm you hold a batch id, not a batch-part or job id.
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
- Could not find a job with id ''.
- No batch found for id ${batchId}
- Batch with id '${batchId}' does not have a batch document.
- Could not find a deployment with id ''.
- Could not find a case instance with id '${caseInstanceId}'.
AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11).
Data as JSON: /api/errors/272af315d967c6b5.
Report an issue: GitHub.