{"record":{"id":"d5e46b9bcd5d52b5","repo":"alibaba/spring-ai-alibaba","slug":"error-d5e46b","errorCode":null,"errorMessage":"数据项删除失败: ","messagePattern":"数据项删除失败: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/impl/DatasetItemServiceImpl.java","lineNumber":176,"sourceCode":"        log.info(\"删除数据项: {}\", id);\n        \n        // 数据验证\n        if (id == null || id <= 0) {\n            throw new IllegalArgumentException(\"数据项ID不能为空且必须大于0\");\n        }\n        \n        // 检查数据项是否存在\n        DatasetItemDO existingItem = datasetItemMapper.selectById(id);\n        if (existingItem == null) {\n            log.warn(\"尝试删除不存在的数据项: {}\", id);\n            throw new RuntimeException(\"数据项不存在: \" + id);\n        }\n        \n\n        int result = datasetItemMapper.deleteById(id);\n        if (result <= 0) {\n            log.error(\"数据项删除失败: {}\", id);\n            throw new RuntimeException(\"数据项删除失败: \" + id);\n        }\n        \n        log.info(\"数据项删除成功: {}\", id);\n    }\n\n    @Override\n    public void batchDelete(List<Long> ids) {\n        log.info(\"批量删除数据项: {}\", JSONObject.toJSONString(ids));\n\n        datasetItemMapper.batchDeleteByIds(ids);\n\n        log.info(\"批量删除数据项完成\");\n    }\n\n\n}\n","sourceCodeStart":158,"sourceCodeEnd":193,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/impl/DatasetItemServiceImpl.java#L158-L193","documentation":"Thrown by DatasetItemServiceImpl.deleteById() when the DELETE statement affects zero rows (datasetItemMapper.deleteById returns <= 0) even though the item was seen to exist moments before. It signals an unexpected persistence failure.","triggerScenarios":"Row deleted concurrently between the existence check and the delete; logical-delete configuration intercepting the delete; database constraint or mapper misconfiguration causing the delete to fail silently.","commonSituations":"Concurrent transactions removing the same item; @TableLogic flagging rows as deleted so selectById sees them but delete semantics differ; DB permission/trigger issues.","solutions":["Retry the operation and re-check whether the item still exists","Log and inspect SQL/MyBatis logs to see why the delete affected 0 rows","Check @TableLogic (logical delete) configuration on DatasetItemDO","Verify DB user has DELETE privileges and no blocking triggers/constraints"],"exampleFix":"// before\nint result = datasetItemMapper.deleteById(id);\nif (result <= 0) { throw new RuntimeException(\"数据项删除失败: \" + id); }\n// after\nint result = datasetItemMapper.deleteById(id);\nif (result <= 0) {\n    if (datasetItemMapper.selectById(id) == null) { return; } // deleted concurrently\n    throw new RuntimeException(\"数据项删除失败: \" + id);\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { service.deleteById(id); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"数据项删除失败\")) { retryOnceThenAlert(id); } else { throw e; } }","preventionTips":["Keep the existence check and delete in one transaction to narrow the race window","Review @TableLogic logical-delete configuration on the entity","Monitor MyBatis SQL logs for 0-row deletes and DB privileges"],"tags":["mybatis","delete","database"],"backgroundTag":"database-write-failed","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}