{"record":{"id":"af741701249b93d0","repo":"alibaba/spring-ai-alibaba","slug":"error-af7417","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/EvaluatorVersionServiceImpl.java","lineNumber":49,"sourceCode":"        // 构建DO对象\n        EvaluatorVersionDO evaluatorVersionDO = EvaluatorVersionDO.builder()\n                .evaluatorId(Long.valueOf(request.getEvaluatorId()))\n                .description(request.getDescription())\n                .version(request.getVersion())\n                .modelConfig(request.getModelConfig())\n                .prompt(request.getPrompt())\n                .variables(request.getVariables())\n                .createTime(LocalDateTime.now())\n                .updateTime(LocalDateTime.now())\n                .build();\n\n        // 插入数据库\n        int result = evaluatorVersionMapper.insert(evaluatorVersionDO);\n        if (result > 0) {\n            log.info(\"评估器版本创建成功: {}\", evaluatorVersionDO.getId());\n            return EvaluatorVersion.fromDO(evaluatorVersionDO);\n        } else {\n            throw new RuntimeException(\"创建评估器版本失败\");\n        }\n    }\n\n    @Override\n    public PageResult<EvaluatorVersion> list(EvaluatorVersionListRequest request) {\n        log.info(\"查询评估器版本列表: {}\", request);\n\n        // 计算分页参数\n        int pageNumber = request.getPageNumber() != null ? request.getPageNumber() : 1;\n        int pageSize = request.getPageSize() != null ? request.getPageSize() : 10;\n        long offset = (pageNumber - 1L) * pageSize;\n\n        // 查询数据\n        List<EvaluatorVersionDO> evaluatorVersionDOList = evaluatorVersionMapper.selectListByEvaluatorId(\n                request.getEvaluatorId(), request.getName(), offset, pageSize);\n        int total = evaluatorVersionMapper.countByEvaluatorId(request.getEvaluatorId(), null);\n\n        // 封装分页结果","sourceCodeStart":31,"sourceCodeEnd":67,"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/EvaluatorVersionServiceImpl.java#L31-L67","documentation":"Thrown by EvaluatorVersionServiceImpl.create when evaluatorVersionMapper.insert returns 0, meaning the new evaluator version row was not persisted. MyBatis insert returning 0 usually indicates a constraint violation surfaced as a no-op or a DB-level failure swallowed by the mapper.","triggerScenarios":"Inserting an evaluator version whose evaluator_id violates a foreign key, a duplicate version number under a unique constraint, or a schema mismatch causing the affected-row count to be 0.","commonSituations":"Creating a version for an evaluator that was deleted concurrently; unique key on (evaluator_id, version) colliding; running against a DB whose schema is behind migrations.","solutions":["Check DB constraints and migrations for evaluator_version table; fix duplicate/foreign-key data","Throw a typed DuplicateVersionException on 0-rows so clients see 409 instead of generic 500","Verify the evaluator referenced by the request still exists before inserting","Inspect server logs / SQL exceptions emitted around the insert for the root cause"],"exampleFix":"// before\nint result = evaluatorVersionMapper.insert(evaluatorVersionDO);\nif (result > 0) { ... } else {\n    throw new RuntimeException(\"创建评估器版本失败\");\n}\n// after\nif (evaluatorMapper.selectById(request.getEvaluatorId()) == null) {\n    throw new EvaluatorNotFoundException(request.getEvaluatorId());\n}\nint result = evaluatorVersionMapper.insert(evaluatorVersionDO);\nif (result <= 0) {\n    throw new EvaluatorVersionCreateException(\"Duplicate or invalid evaluator version: \" + request.getVersion());\n}","handlingStrategy":"validation","validationCode":"if (evaluatorMapper.selectById(request.getEvaluatorId()) == null) throw new EvaluatorNotFoundException(request.getEvaluatorId());\nif (evaluatorVersionMapper.selectByVersion(request.getEvaluatorId(), request.getVersion()) != null) throw new DuplicateVersionException();","typeGuard":"boolean canCreateVersion(EvaluatorVersionCreateRequest r) { return r != null && r.getEvaluatorId() != null && evaluatorMapper.selectById(r.getEvaluatorId()) != null; }","tryCatchPattern":"try { return evaluatorVersionService.create(request); } catch (RuntimeException e) { log.error(\"version create failed\", e); throw new ResponseStatusException(HttpStatus.CONFLICT, e.getMessage()); }","preventionTips":["Validate referenced evaluator exists first","Enforce unique (evaluator_id, version) in app code before insert","Keep DB schema migrations in sync"],"tags":["database","insert","persistence"],"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"}