{"record":{"id":"816eddc4595e5b24","repo":"flowable/flowable-engine","slug":"latest-can-only-be-used-together-with-a-deployment-816edd","errorCode":null,"errorMessage":"latest can only be used together with a deployment key","messagePattern":"latest can only be used together with a deployment key","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/repository/CmmnDeploymentQueryImpl.java","lineNumber":177,"sourceCode":"            throw new FlowableIllegalArgumentException(\"parentDeploymentIdLike is null\");\n        }\n        this.parentDeploymentIdLike = parentDeploymentIdLike;\n        return this;\n    }\n    \n    @Override\n    public CmmnDeploymentQueryImpl parentDeploymentIds(List<String> parentDeploymentIds) {\n        if (parentDeploymentIds == null) {\n            throw new FlowableIllegalArgumentException(\"parentDeploymentIds is null\");\n        }\n        this.parentDeploymentIds = parentDeploymentIds;\n        return this;\n    }\n    \n    @Override\n    public CmmnDeploymentQueryImpl latest() {\n        if (key == null) {\n            throw new FlowableIllegalArgumentException(\"latest can only be used together with a deployment key\");\n        }\n\n        this.latest = true;\n        return this;\n    }\n\n    // sorting ////////////////////////////////////////////////////////\n\n    @Override\n    public CmmnDeploymentQuery orderByDeploymentId() {\n        return orderBy(CmmnDeploymentQueryProperty.DEPLOYMENT_ID);\n    }\n\n    @Override\n    public CmmnDeploymentQuery orderByDeploymentTime() {\n        return orderBy(CmmnDeploymentQueryProperty.DEPLOY_TIME);\n    }\n","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/repository/CmmnDeploymentQueryImpl.java#L159-L195","documentation":"Thrown by CmmnDeploymentQueryImpl.latest() when called before deploymentKey(). The 'latest' flag is only meaningful as 'latest deployment with this key'; without a key the semantics are undefined, so Flowable rejects the combination.","triggerScenarios":"Calling createCmmnDeploymentQuery().latest() without a preceding deploymentKey(...) call, or calling latest() after building a query filtered only by category/tenant.","commonSituations":"Trying to fetch 'the latest deployment' overall rather than per key; reordering fluent calls so latest() runs before deploymentKey(); copy-pasted query code that dropped the key filter.","solutions":["Call deploymentKey(\"yourKey\") before .latest(): createCmmnDeploymentQuery().deploymentKey(key).latest()","If you truly want the newest deployment regardless of key, sort by deployment time and take the first result instead of using latest()","Reorder the fluent chain so the key filter precedes latest()"],"exampleFix":"// before\nCmmnDeployment d = repositoryService.createCmmnDeploymentQuery().latest().singleResult();\n// after\nCmmnDeployment d = repositoryService.createCmmnDeploymentQuery()\n    .deploymentKey(\"myDeploymentKey\")\n    .latest()\n    .singleResult();","handlingStrategy":"validation","validationCode":"if (key == null) {\n    throw new IllegalStateException(\"deploymentKey must be set before latest()\");\n}\nCmmnDeployment d = repositoryService.createCmmnDeploymentQuery()\n    .deploymentKey(key).latest().singleResult();","typeGuard":null,"tryCatchPattern":"try {\n    CmmnDeployment d = query.latest().singleResult();\n} catch (FlowableIllegalArgumentException e) {\n    // add the missing deploymentKey(...) call or use a different strategy\n}","preventionTips":["Always pair latest() with a preceding deploymentKey() call","Encapsulate 'latest deployment by key' in one helper method","Do not use latest() for global 'newest deployment' queries; order by deployment time instead"],"tags":["java","flowable","query","api-misuse"],"backgroundTag":"conflicting-config-options","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}