{"record":{"id":"f82e3020cb0f145b","repo":"alibaba/COLA","slug":"companyname-has-already-existed-you-can-not-ad-f82e30","errorCode":null,"errorMessage":"${companyName} has already existed, you can not add it","messagePattern":"(.+?) has already existed, you can not add it","errorType":"exception","errorClass":"BizException","httpStatus":null,"severity":"warning","filePath":"cola-archetypes/cola-archetype-web/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/Customer.java","lineNumber":37,"sourceCode":"    private String companyName;\n    private SourceType sourceType;\n    private CompanyType companyType;\n\n    public Customer() {\n    }\n\n    public boolean isBigCompany() {\n        return registeredCapital > 10000000; //注册资金大于1000万的是大企业\n    }\n\n    public boolean isSME() {\n        return registeredCapital > 10000 && registeredCapital < 1000000; //注册资金大于10万小于100万的为中小企业\n    }\n\n    public void checkConflict(){\n        //Per different biz, the check policy could be different, if so, use ExtensionPoint\n        if(\"ConflictCompanyName\".equals(this.companyName)){\n            throw new BizException(this.companyName+\" has already existed, you can not add it\");\n        }\n\n    }\n}\n","sourceCodeStart":19,"sourceCodeEnd":42,"githubUrl":"https://github.com/alibaba/COLA/blob/352e1a867538d9cd40e1b11e4028fa652fc97557/cola-archetypes/cola-archetype-web/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/Customer.java#L19-L42","documentation":"Domain-level conflict check in the web archetype's Customer entity: checkConflict() throws BizException (message includes the company name) when companyName equals \"ConflictCompanyName\". It represents the duplicate-company-name invariant of the Customer aggregate.","triggerScenarios":"Calling customer.checkConflict() during customer creation when this.companyName is \"ConflictCompanyName\".","commonSituations":"Demo payloads in the generated web app; tests exercising the conflict branch; template code left in place instead of a real per-business conflict policy.","solutions":["Change the companyName value in the request.","Implement the real conflict policy via repository lookup or ExtensionPoint instead of the literal string comparison.","Catch BizException in the executor layer and return a structured error response."],"exampleFix":"// before\nif(\"ConflictCompanyName\".equals(this.companyName)){\n    throw new BizException(this.companyName+\" has already existed, you can not add it\");\n}\n// after\nif(customerRepository.existsByCompanyName(this.companyName)){\n    throw new BizException(this.companyName+\" has already existed, you can not add it\");\n}","handlingStrategy":"validation","validationCode":"if (\"ConflictCompanyName\".equals(customer.getCompanyName())) {\n    return Response.buildFailure(\"CUSTOMER_CONFLICT\", customer.getCompanyName() + \" has already existed\");\n}\ncustomer.checkConflict();","typeGuard":null,"tryCatchPattern":"try {\n    customer.checkConflict();\n} catch (BizException e) {\n    return Response.buildFailure(ErrorCode.B_CUSTOMER_companyNameConflict.getErrCode(), e.getMessage());\n}","preventionTips":["Perform uniqueness validation in the executor before invoking the domain entity.","Replace the hard-coded string with a repository or ExtensionPoint based conflict policy.","Keep conflict messaging user-facing (avoid leaking sentinel values) by catching BizException centrally."],"tags":["domain-model","uniqueness-conflict","cola"],"backgroundTag":"schema-validation-failed","analyzedSha":"352e1a867538d9cd40e1b11e4028fa652fc97557","analyzedAt":"2026-09-08T00:46:23.972Z","contentChangedAt":"2026-09-08T00:46:23.972Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}