{"record":{"id":"2ee6d39dde6045a0","repo":"elunez/eladmin","slug":"a-new-job-cannot-already-have-an-id","errorCode":null,"errorMessage":"A new job cannot already have an ID","messagePattern":"A new job cannot already have an ID","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"warning","filePath":"eladmin-system/src/main/java/me/zhengjie/modules/system/rest/JobController.java","lineNumber":71,"sourceCode":"    @PreAuthorize(\"@el.check('job:list')\")\n    public void exportJob(HttpServletResponse response, JobQueryCriteria criteria) throws IOException {\n        jobService.download(jobService.queryAll(criteria), response);\n    }\n\n    @ApiOperation(\"查询岗位\")\n    @GetMapping\n    @PreAuthorize(\"@el.check('job:list','user:list')\")\n    public ResponseEntity<PageResult<JobDto>> queryJob(JobQueryCriteria criteria, Pageable pageable){\n        return new ResponseEntity<>(jobService.queryAll(criteria, pageable),HttpStatus.OK);\n    }\n\n    @Log(\"新增岗位\")\n    @ApiOperation(\"新增岗位\")\n    @PostMapping\n    @PreAuthorize(\"@el.check('job:add')\")\n    public ResponseEntity<Object> createJob(@Validated @RequestBody Job resources){\n        if (resources.getId() != null) {\n            throw new BadRequestException(\"A new \"+ ENTITY_NAME +\" cannot already have an ID\");\n        }\n        jobService.create(resources);\n        return new ResponseEntity<>(HttpStatus.CREATED);\n    }\n\n    @Log(\"修改岗位\")\n    @ApiOperation(\"修改岗位\")\n    @PutMapping\n    @PreAuthorize(\"@el.check('job:edit')\")\n    public ResponseEntity<Object> updateJob(@Validated(Job.Update.class) @RequestBody Job resources){\n        jobService.update(resources);\n        return new ResponseEntity<>(HttpStatus.NO_CONTENT);\n    }\n\n    @Log(\"删除岗位\")\n    @ApiOperation(\"删除岗位\")\n    @DeleteMapping\n    @PreAuthorize(\"@el.check('job:del')\")","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/JobController.java#L53-L89","documentation":"Thrown by JobController.createJob (line 71) when POST /api/job is called with an id in the body. Positions (岗位) follow the standard eladmin create contract: identity is generated server-side, and an id on create is rejected with 400 before jobService.create touches the database.","triggerScenarios":"Job dialog not reset between editing an existing position and creating one; POSTing a JobDto obtained from the paginated GET /api/job list; migration scripts inserting positions from another system with source ids included.","commonSituations":"Shared add/edit dialog with leftover form state; testers copying a PUT body into POST; scripts syncing sys_job between environments.","solutions":["Strip id from the request body before POST /api/job.","Reset the job form model (id = null) on dialog open for create mode.","Use PUT /api/job with the existing id when the intent is actually an update."],"exampleFix":"// before\naxios.post('/api/job', this.form)\n// after\nconst { id, ...payload } = this.form;\naxios.post('/api/job', payload)","handlingStrategy":"validation","validationCode":"const payload = { name: form.name, enabled: form.enabled, sort: form.sort }; // no id\naxios.post('/api/job', payload);","typeGuard":"const isCreateSafe = (job) => job.id == null;","tryCatchPattern":null,"preventionTips":["Clear the job dialog form on open.","Use PUT when an id is present — route by id presence in a submit() helper."],"tags":["rest-api","validation","eladmin","job","crud"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}