{"record":{"id":"12f55aabfbdffeb4","repo":"flowable/flowable-engine","slug":"cannot-associate-already-associated-with-disas","errorCode":null,"errorMessage":"Cannot associate , already associated with . Disassociate first!","messagePattern":"Cannot associate , already associated with \\. Disassociate first!","errorType":"exception","errorClass":"FlowableCdiException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cdi/src/main/java/org/flowable/cdi/impl/context/DefaultContextAssociationManager.java","lineNumber":155,"sourceCode":"\r\n    protected ScopedAssociation getScopedAssociation() {\r\n        return ProgrammaticBeanLookup.lookup(getBroadestActiveContext(), beanManager);\r\n    }\r\n\r\n    @Override\r\n    public void setExecution(Execution execution) {\r\n        if (execution == null) {\r\n            throw new FlowableCdiException(\"Cannot associate with execution: null\");\r\n        }\r\n\r\n        if (Context.getCommandContext() != null) {\r\n            throw new FlowableCdiException(\"Cannot work with scoped associations inside command context.\");\r\n        }\r\n\r\n        ScopedAssociation scopedAssociation = getScopedAssociation();\r\n        Execution associatedExecution = scopedAssociation.getExecution();\r\n        if (associatedExecution != null && !associatedExecution.getId().equals(execution.getId())) {\r\n            throw new FlowableCdiException(\"Cannot associate \" + execution + \", already associated with \" + associatedExecution + \". Disassociate first!\");\r\n        }\r\n\r\n        if (LOGGER.isTraceEnabled()) {\r\n            LOGGER.trace(\"Associating {} (@{})\", execution, scopedAssociation.getClass().getAnnotations()[0].annotationType().getSimpleName());\r\n        }\r\n        scopedAssociation.setExecution(execution);\r\n    }\r\n\r\n    @Override\r\n    public void disAssociate() {\r\n        if (Context.getCommandContext() != null) {\r\n            throw new FlowableCdiException(\"Cannot work with scoped associations inside command context.\");\r\n        }\r\n        ScopedAssociation scopedAssociation = getScopedAssociation();\r\n        if (scopedAssociation.getExecution() == null) {\r\n            throw new FlowableException(\"Cannot disassociate execution, no \" + scopedAssociation.getClass().getAnnotations()[0].annotationType().getSimpleName() + \" execution associated. \");\r\n        }\r\n        if (LOGGER.isTraceEnabled()) {\r","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cdi/src/main/java/org/flowable/cdi/impl/context/DefaultContextAssociationManager.java#L137-L173","documentation":"setExecution() enforces one execution per scoped association: if the current CDI scope already holds an execution with a different id, re-associating without clearing first throws this FlowableCdiException ('Cannot associate X, already associated with Y. Disassociate first!').","triggerScenarios":"Calling businessProcess.associateExecution(execB) while the same conversation/request scope still has execA associated; typical in long conversations where a second process interaction starts without disAssociate().","commonSituations":"Handling multiple process instances in one CDI conversation (e.g. user opens a second task without finishing the first); missing @CompleteTask(endConversation=true) so the association leaks across requests.","solutions":["Call businessProcess.disAssociate() before associating a different execution.","End the conversation when a task/process interaction completes: @CompleteTask(endConversation = true).","If the same execution is intended, verify ids match rather than re-associating (association is idempotent only for the same id)."],"exampleFix":"// before\nbusinessProcess.associateExecution(newExecution);\n// after\nbusinessProcess.disAssociate();\nbusinessProcess.associateExecution(newExecution);","handlingStrategy":"try-catch","validationCode":"Execution current = /* track in scope */ null;\nif (current != null && !current.getId().equals(newExecution.getId())) businessProcess.disAssociate();","typeGuard":"null","tryCatchPattern":"try { businessProcess.associateExecution(newExec); } catch (FlowableCdiException e) { businessProcess.disAssociate(); businessProcess.associateExecution(newExec); }","preventionTips":["Always disAssociate before associating a different execution","Use @CompleteTask(endConversation = true) to avoid leaking associations across interactions","Track which execution is associated within each conversation"],"tags":["cdi","association-conflict","scoped-association"],"backgroundTag":"invalid-state-transition","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"}