elunez/eladmin · error · EntityExistException
Job with name {} existed
Error message
Job with name {} existed What it means
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.
Source
Thrown at eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/JobServiceImpl.java:81
@Override
public JobDto findById(Long id) {
String key = CacheKey.JOB_ID + id;
Job job = redisUtils.get(key, Job.class);
if(job == null){
job = jobRepository.findById(id).orElseGet(Job::new);
ValidationUtil.isNull(job.getId(),"Job","id",id);
redisUtils.set(key, job, 1, TimeUnit.DAYS);
}
return jobMapper.toDto(job);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(Job resources) {
Job job = jobRepository.findByName(resources.getName());
if(job != null){
throw new EntityExistException(Job.class,"name",resources.getName());
}
jobRepository.save(resources);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(Job resources) {
Job job = jobRepository.findById(resources.getId()).orElseGet(Job::new);
Job old = jobRepository.findByName(resources.getName());
if(old != null && !old.getId().equals(resources.getId())){
throw new EntityExistException(Job.class,"name",resources.getName());
}
ValidationUtil.isNull( job.getId(),"Job","id",resources.getId());
resources.setId(job.getId());
jobRepository.save(resources);
// 删除缓存
delCaches(resources.getId());
}View on GitHub (pinned to 55fbf70595)
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.
Defensive patterns
Strategy: validation
Validate before calling
// Pre-check uniqueness (name is the natural key for jobs)
const { data } = await axios.get('/api/job', { params: { blurry: form.name } });
const clash = data.content.some(j => j.name === form.name.trim());
if (clash) { notifyError('岗位名称已存在'); return; }
await axios.post('/api/job', form); Try / catch
Catch the 400 EntityExistException and focus the name input with the duplicate message; do not silently retry.
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- A new job cannot already have an ID
- {entity} 不存在: {parameter} is {value}
- A new dept cannot already have an ID
- A new dict cannot already have an ID
- A new dictDetail cannot already have an ID
AI-assisted analysis of elunez/eladmin@55fbf70595 (2026-08-14).
Data as JSON: /api/errors/8717ebb6306064ae.
Report an issue: GitHub.