alibaba/spring-ai-alibaba · error · RuntimeException
数据项删除失败:
Error message
数据项删除失败:
What it means
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.
Source
Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/impl/DatasetItemServiceImpl.java:176
log.info("删除数据项: {}", id);
// 数据验证
if (id == null || id <= 0) {
throw new IllegalArgumentException("数据项ID不能为空且必须大于0");
}
// 检查数据项是否存在
DatasetItemDO existingItem = datasetItemMapper.selectById(id);
if (existingItem == null) {
log.warn("尝试删除不存在的数据项: {}", id);
throw new RuntimeException("数据项不存在: " + id);
}
int result = datasetItemMapper.deleteById(id);
if (result <= 0) {
log.error("数据项删除失败: {}", id);
throw new RuntimeException("数据项删除失败: " + id);
}
log.info("数据项删除成功: {}", id);
}
@Override
public void batchDelete(List<Long> ids) {
log.info("批量删除数据项: {}", JSONObject.toJSONString(ids));
datasetItemMapper.batchDeleteByIds(ids);
log.info("批量删除数据项完成");
}
}
View on GitHub (pinned to f82da0b50f)
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
Example fix
// before
int result = datasetItemMapper.deleteById(id);
if (result <= 0) { throw new RuntimeException("数据项删除失败: " + id); }
// after
int result = datasetItemMapper.deleteById(id);
if (result <= 0) {
if (datasetItemMapper.selectById(id) == null) { return; } // deleted concurrently
throw new RuntimeException("数据项删除失败: " + id);
} Defensive patterns
Strategy: retry
Try / catch
try { service.deleteById(id); } catch (RuntimeException e) { if (e.getMessage().startsWith("数据项删除失败")) { retryOnceThenAlert(id); } else { throw e; } } Prevention
- 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
When it happens
Trigger: 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.
Common situations: Concurrent transactions removing the same item; @TableLogic flagging rows as deleted so selectById sees them but delete semantics differ; DB permission/trigger issues.
Related errors
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/d5e46b9bcd5d52b5.
Report an issue: GitHub.