alibaba/spring-ai-alibaba · error · RuntimeException

数据项不存在:

Error message

数据项不存在: 

What it means

Thrown by DatasetItemServiceImpl.deleteById() when datasetItemMapper.selectById(id) returns null, meaning no dataset item row with that id exists. The delete is aborted with a descriptive message instead of silently doing nothing.

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:169

        return getById(request.getId());
    }

    @Override

    public void deleteById(Long id) {
        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);

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Check the item exists before deleting (or handle the absence gracefully as idempotent delete)
  2. Refresh the item list and use a current id
  3. Confirm the service connects to the intended database/environment
  4. If concurrent deletes are expected, catch this error and treat the item as already removed

Example fix

// before
datasetItemService.deleteById(itemId); // itemId already deleted
// after
try {
    datasetItemService.deleteById(itemId);
} catch (RuntimeException e) {
    // treat as idempotent success if item no longer exists
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (id != null && datasetItemMapper.selectById(id) == null) { log.info("item {} already gone", id); return; }

Try / catch

try { service.deleteById(id); } catch (RuntimeException e) { if (e.getMessage().startsWith("数据项不存在")) { /* idempotent: already deleted */ } else { throw e; } }

Prevention

When it happens

Trigger: Calling deleteById(id) for an item already deleted, an id from another dataset/environment, or an id that never existed.

Common situations: Double-delete from duplicate UI clicks or retry logic; stale front-end list after another user removed the item; wrong database profile.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/be2935d00497a26c. Report an issue: GitHub.