{"record":{"id":"7f8893cbe137c176","repo":"elunez/eladmin","slug":"a-new-quartzjob-cannot-already-have-an-id","errorCode":null,"errorMessage":"A new quartzJob cannot already have an ID","messagePattern":"A new quartzJob cannot already have an ID","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"eladmin-system/src/main/java/me/zhengjie/modules/quartz/rest/QuartzJobController.java","lineNumber":88,"sourceCode":"    @PreAuthorize(\"@el.check('timing:list')\")\n    public void exportQuartzJobLog(HttpServletResponse response, JobQueryCriteria criteria) throws IOException {\n        quartzJobService.downloadLog(quartzJobService.queryAllLog(criteria), response);\n    }\n\n    @ApiOperation(\"查询任务执行日志\")\n    @GetMapping(value = \"/logs\")\n    @PreAuthorize(\"@el.check('timing:list')\")\n    public ResponseEntity<PageResult<QuartzLog>> queryQuartzJobLog(JobQueryCriteria criteria, Pageable pageable){\n        return new ResponseEntity<>(quartzJobService.queryAllLog(criteria,pageable), HttpStatus.OK);\n    }\n\n    @Log(\"新增定时任务\")\n    @ApiOperation(\"新增定时任务\")\n    @PostMapping\n    @PreAuthorize(\"@el.check('timing:add')\")\n    public ResponseEntity<Object> createQuartzJob(@Validated @RequestBody QuartzJob resources){\n        if (resources.getId() != null) {\n            throw new BadRequestException(\"A new \"+ ENTITY_NAME +\" cannot already have an ID\");\n        }\n        // 验证Bean是不是合法的，合法的定时任务 Bean 需要用 @Service 定义\n        checkBean(resources.getBeanName());\n        quartzJobService.create(resources);\n        return new ResponseEntity<>(HttpStatus.CREATED);\n    }\n\n    @Log(\"修改定时任务\")\n    @ApiOperation(\"修改定时任务\")\n    @PutMapping\n    @PreAuthorize(\"@el.check('timing:edit')\")\n    public ResponseEntity<Object> updateQuartzJob(@Validated(QuartzJob.Update.class) @RequestBody QuartzJob resources){\n        // 验证Bean是不是合法的，合法的定时任务 Bean 需要用 @Service 定义\n        checkBean(resources.getBeanName());\n        quartzJobService.update(resources);\n        return new ResponseEntity<>(HttpStatus.NO_CONTENT);\n    }\n","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-system/src/main/java/me/zhengjie/modules/quartz/rest/QuartzJobController.java#L70-L106","documentation":"Standard eladmin REST guard in QuartzJobController.createQuartzJob: a POST /api/quartz/jobs body whose JSON includes a non-null 'id' is rejected because creating a new entity must not carry a primary key. The id is normally auto-generated by JPA, so a client-supplied id indicates the wrong endpoint or a stale frontend payload.","triggerScenarios":"POST /api/quartz/jobs with a body like {\"id\":5,\"jobName\":\"x\",...}. Commonly caused by a frontend 'add' form reusing an edited job object, or by copy-pasting an update (PUT) request body into a create (POST) request.","commonSituations":"Frontend edit dialog not clearing the id field before switching to create mode; API clients scripting job creation from an exported job list; tools that echo back the full object on save.","solutions":["Remove the 'id' field from the request body (or set it to null) when calling POST /api/quartz/jobs.","Use PUT /api/quartz/jobs when you actually intend to update an existing job.","In the frontend form, reset the quartzJob object to a blank template when opening the 'new' dialog."],"exampleFix":"// before\nPOST /api/quartz/jobs\n{\"id\": 3, \"jobName\": \"job\", \"cronExpression\": \"0 0 * * * ?\", \"beanName\": \"runTaskJob\"}\n// after\nPOST /api/quartz/jobs\n{\"jobName\": \"job\", \"cronExpression\": \"0 0 * * * ?\", \"beanName\": \"runTaskJob\"}","handlingStrategy":"validation","validationCode":"// client-side guard before POST\nif (job.getId() != null) { throw new Error('Send PUT /api/quartz/jobs to update, or clear id to create'); }\nawait axios.post('/api/quartz/jobs', job);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reset the form model to a blank object when opening the create dialog.","Keep create (POST, no id) and update (PUT, with id) payloads separate in API client code.","Add a frontend unit test asserting the create payload has no id key."],"tags":["rest","validation","quartz","api-contract"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}