{"record":{"id":"119c7023fdfc6891","repo":"hs-web/hsweb-framework","slug":"not-found","errorCode":null,"errorMessage":"Not Found","messagePattern":"Not Found","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/web/reactive/ReactiveServiceSaveController.java","lineNumber":180,"sourceCode":"     * }\n     * </pre>\n     *\n     * @param payload payload\n     * @return 是否成功\n     */\n    @PutMapping(\"/{id}\")\n    @SaveAction\n    @Operation(summary = \"根据ID修改数据\")\n    default Mono<Boolean> update(@PathVariable K id, @RequestBody Mono<E> payload) {\n\n        return Authentication\n                .currentReactive()\n                .flatMap(auth -> payload.map(entity -> applyAuthentication(entity, auth)))\n                .switchIfEmpty(payload)\n                .flatMap(entity -> getService().updateById(id, Mono.just(entity)))\n                .doOnNext(i -> {\n                    if (i == 0) {\n                        throw new NotFoundException();\n                    }\n                })\n                .thenReturn(true);\n\n    }\n}\n","sourceCodeStart":162,"sourceCodeEnd":187,"githubUrl":"https://github.com/hs-web/hsweb-framework/blob/b2cfc85a57c70bf5b5cf6e7edae2d37102652ec8/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/web/reactive/ReactiveServiceSaveController.java#L162-L187","documentation":"A NotFoundException thrown in the doOnNext callback of ReactiveServiceSaveController.update (PUT /{id}) when the underlying service's updateById returns 0 updated rows, meaning no entity with the given path-variable id exists (or none matched authorization-modified entity data). It fires because the requested record was deleted or never existed, and the controller translates the 0-row result into a 404 'Not Found' response rather than silently reporting success.","triggerScenarios":"PUT/PATCH to the reactive CRUD endpoint with an id that does not exist in storage, or an entity filtered out by query/permission conditions so updateById matches 0 rows.","commonSituations":"Client uses a stale or deleted id; wrong tenant/workspace scope filters the row out; race where another request deleted the entity first.","solutions":["Verify the entity id exists before calling the update endpoint","Return create-not-update flow if the record should be created when missing","Check query conditions (tenant, data scope) that could exclude the row","Handle 404 on the client and refresh entity state"],"exampleFix":"// before\nservice.updateById(id, Mono.just(entity));\n// after\nservice.findById(id).switchIfEmpty(Mono.error(new NotFoundException())).then(service.updateById(id, Mono.just(entity)));","handlingStrategy":"try-catch","validationCode":"boolean exists = service.createQuery().where(\"id\", id).fetchOne().isPresent();\nif (!exists) return Mono.error(new NotFoundException());","typeGuard":"Mono<Entity> existing = service.findById(id);\n// proceed only if existing has a value before calling updateById","tryCatchPattern":"service.updateById(id, Mono.just(entity))\n    .doOnNext(i -> { if (i == 0) throw new NotFoundException(); })\n    .onErrorResume(NotFoundException.class, e -> {\n        log.warn(\"update target not found: {}\", id);\n        return Mono.just(false);\n    });","preventionTips":["Check entity existence before update","Refresh stale ids after deletes","Scope updates with correct tenant/query conditions","Return 404 semantics explicitly on the client"],"tags":["rest","crud","not-found"],"backgroundTag":"record-not-found","analyzedSha":"b2cfc85a57c70bf5b5cf6e7edae2d37102652ec8","analyzedAt":"2026-09-13T09:05:02.172Z","contentChangedAt":"2026-09-13T09:05:02.172Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}