{"record":{"id":"9e616ab23540f090","repo":"flowable/flowable-engine","slug":"the-deployment-contains-event-definition-with-the","errorCode":null,"errorMessage":"The deployment contains event definition with the same key, this is not allowed","messagePattern":"The deployment contains event definition with the same key, this is not allowed","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-event-registry/src/main/java/org/flowable/eventregistry/impl/deployer/EventDefinitionDeploymentHelper.java","lineNumber":45,"sourceCode":"import org.flowable.eventregistry.impl.util.CommandContextUtil;\n\n/**\n * Methods for working with deployments. Much of the actual work of {@link EventDefinitionDeployer} is done by orchestrating the different pieces of work this class does; by having them here, we allow\n * other deployers to make use of them.\n */\npublic class EventDefinitionDeploymentHelper {\n\n    /**\n     * Verifies that no two event definitions share the same key, to prevent database unique index violation.\n     * \n     * @throws FlowableException\n     *             if any two event definitions have the same key\n     */\n    public void verifyEventDefinitionsDoNotShareKeys(Collection<EventDefinitionEntity> eventDefinitions) {\n        Set<String> keySet = new LinkedHashSet<>();\n        for (EventDefinitionEntity eventDefinition : eventDefinitions) {\n            if (keySet.contains(eventDefinition.getKey())) {\n                throw new FlowableException(\"The deployment contains event definition with the same key, this is not allowed\");\n            }\n            keySet.add(eventDefinition.getKey());\n        }\n    }\n\n    /**\n     * Updates all the event definition entities to match the deployment's values for tenant, engine version, and deployment id.\n     */\n    public void copyDeploymentValuesToEventDefinitions(EventDeploymentEntity deployment, List<EventDefinitionEntity> eventDefinitions) {\n        String tenantId = deployment.getTenantId();\n        String deploymentId = deployment.getId();\n\n        for (EventDefinitionEntity eventDefinition : eventDefinitions) {\n\n            // event definition inherits the tenant id\n            if (tenantId != null) {\n                eventDefinition.setTenantId(tenantId);\n            }","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-event-registry/src/main/java/org/flowable/eventregistry/impl/deployer/EventDefinitionDeploymentHelper.java#L27-L63","documentation":"During event-registry deployment, Flowable scans all event definitions in the deployment and rejects duplicates: two definitions with the same key cannot coexist in one deployment. Event definitions are keyed by their 'key' attribute, which must be unique so persisted instances can be resolved unambiguously. The check uses a LinkedHashSet and throws on the first duplicate found.","triggerScenarios":"Calling deploy() (directly or via EventModelBuilder / repository deployer) with a deployment whose resource set contains two or more .event JSON files (or programmatically added definitions) that share the same key value.","commonSituations":"Copying an event JSON file to tweak it but forgetting to change its key; merging branches that each added a definition with the same key; a build script or test fixture accidentally packaging the same resource twice.","solutions":["Give every event definition JSON a unique 'key' value before deploying","Remove the duplicate resource from the deployment (check the resources added to the DeploymentBuilder)","If two definitions intentionally share a key, deploy them in separate deployments (versioning then applies)","Search the deployment resources for duplicate key values with a pre-deploy validation script"],"exampleFix":"// before: deploy/events/orderCreated.event -> {\"key\":\"orderCreated\", ...}\n// deploy/events/orderCreatedV2.event -> {\"key\":\"orderCreated\", ...}\n// after\n// deploy/events/orderCreatedV2.event -> {\"key\":\"orderCreatedV2\", ...}","handlingStrategy":"validation","validationCode":"Set<String> seen = new HashSet<>();\nfor (EventDefinitionEntity def : eventDefinitions) {\n    if (!seen.add(def.getKey())) {\n        throw new IllegalArgumentException(\"Duplicate event key: \" + def.getKey());\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    deploymentBuilder.deploy();\n} catch (FlowableException e) {\n    if (e.getMessage().contains(\"same key\")) { /* de-duplicate resources and retry */ }\n}","preventionTips":["Enforce unique keys in event JSON files via a unit test scanning resources","Name event files after their key to make duplicates obvious in review","Adopt versioned keys (e.g. orderCreated.v2) instead of reusing keys"],"tags":["flowable","event-registry","deployment","duplicate-key"],"backgroundTag":"duplicate-key-conflict","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"}