{"record":{"id":"8717ebb6306064ae","repo":"elunez/eladmin","slug":"job-with-name-existed","errorCode":null,"errorMessage":"Job with name {} existed","messagePattern":"Job with name (.+?) existed","errorType":"exception","errorClass":"EntityExistException","httpStatus":400,"severity":"error","filePath":"eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/JobServiceImpl.java","lineNumber":81,"sourceCode":"\n    @Override\n    public JobDto findById(Long id) {\n        String key = CacheKey.JOB_ID + id;\n        Job job = redisUtils.get(key, Job.class);\n        if(job == null){\n            job = jobRepository.findById(id).orElseGet(Job::new);\n            ValidationUtil.isNull(job.getId(),\"Job\",\"id\",id);\n            redisUtils.set(key, job, 1, TimeUnit.DAYS);\n        }\n        return jobMapper.toDto(job);\n    }\n\n    @Override\n    @Transactional(rollbackFor = Exception.class)\n    public void create(Job resources) {\n        Job job = jobRepository.findByName(resources.getName());\n        if(job != null){\n            throw new EntityExistException(Job.class,\"name\",resources.getName());\n        }\n        jobRepository.save(resources);\n    }\n\n    @Override\n    @Transactional(rollbackFor = Exception.class)\n    public void update(Job resources) {\n        Job job = jobRepository.findById(resources.getId()).orElseGet(Job::new);\n        Job old = jobRepository.findByName(resources.getName());\n        if(old != null && !old.getId().equals(resources.getId())){\n            throw new EntityExistException(Job.class,\"name\",resources.getName());\n        }\n        ValidationUtil.isNull( job.getId(),\"Job\",\"id\",resources.getId());\n        resources.setId(job.getId());\n        jobRepository.save(resources);\n        // 删除缓存\n        delCaches(resources.getId());\n    }","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/JobServiceImpl.java#L63-L99","documentation":"Thrown by JobServiceImpl.create (line 81) as EntityExistException(Job.class, \"name\", name), rendered 'Job with name <val> existed' (message built in EntityExistException.generateMessage). sys_job enforces a unique job name at the application layer before save; the global handler maps EntityExistException to a 400 with this text.","triggerScenarios":"POST /api/job with a name that already exists in sys_job (e.g. creating '人事' twice); concurrent double-submit of the create form creating a race between the findByName check and the save; data imports replaying jobs that were never deleted.","commonSituations":"Operators clicking save twice; seed scripts run twice against the same database; names differing only by whitespace/case since the check is exact-match findByName.","solutions":["Pick a different, non-duplicate name for the position.","Make the create idempotent in the client (disable the submit button while pending) to stop double-submits.","For imports, check existence first (query by name) and skip or PUT-update existing jobs.","Optionally add a unique constraint on sys_job.name in the DB as a race-condition backstop."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Pre-check uniqueness (name is the natural key for jobs)\nconst { data } = await axios.get('/api/job', { params: { blurry: form.name } });\nconst clash = data.content.some(j => j.name === form.name.trim());\nif (clash) { notifyError('岗位名称已存在'); return; }\nawait axios.post('/api/job', form);","typeGuard":null,"tryCatchPattern":"Catch the 400 EntityExistException and focus the name input with the duplicate message; do not silently retry.","preventionTips":["Disable the submit button while a create is pending (double-submit race).","Trim names client-side; treat name as globally unique in UI copy.","For imports, upsert by name instead of blind POST."],"tags":["uniqueness","eladmin","job","crud","duplicate"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}