{"record":{"id":"a21d8889c7cac023","repo":"jeecgboot/JeecgBoot","slug":"parentcode","errorCode":null,"errorMessage":"该编码【${parentCode}】不存在，请核实!","messagePattern":"该编码【(.+?)】不存在，请核实!","errorType":"exception","errorClass":"JeecgBootException","httpStatus":null,"severity":"error","filePath":"jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/resources/jeecg/code-template-online/default/tree/java/${bussiPackage}/${entityPackage}/service/impl/${entityName}ServiceImpl.javai","lineNumber":142,"sourceCode":"                }\n            }else{\n                if(!mapList.contains(data)){\n                    mapList.add(data);\n                }\n            }\n        }\n        return mapList;\n    }\n\n    @Override\n    public List<SelectTreeModel> queryListByCode(String parentCode) {\n        String pid = ROOT_PID_VALUE;\n        if (oConvertUtils.isNotEmpty(parentCode)) {\n            LambdaQueryWrapper<${entityName}> queryWrapper = new LambdaQueryWrapper<>();\n            queryWrapper.eq(${entityName}::get${pidFieldName?cap_first}, parentCode);\n            List<${entityName}> list = baseMapper.selectList(queryWrapper);\n            if (list == null || list.size() == 0) {\n                throw new JeecgBootException(\"该编码【\" + parentCode + \"】不存在，请核实!\");\n            }\n            if (list.size() > 1) {\n                throw new JeecgBootException(\"该编码【\" + parentCode + \"】存在多个，请核实!\");\n            }\n            pid = list.get(0).getId();\n        }\n        return baseMapper.queryListByPid(pid, null);\n    }\n\n    @Override\n    public List<SelectTreeModel> queryListByPid(String pid) {\n        if (oConvertUtils.isEmpty(pid)) {\n            pid = ROOT_PID_VALUE;\n        }\n        return baseMapper.queryListByPid(pid, null);\n    }\n\n\t/**","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/resources/jeecg/code-template-online/default/tree/java/${bussiPackage}/${entityPackage}/service/impl/${entityName}ServiceImpl.javai#L124-L160","documentation":"Thrown as JeecgBootException from the generated tree service's queryListByCode method when the provided parentCode does not match any record in the database (the query returns null or an empty list). This method looks up a node by its parent-code field value to find its ID, then queries children by that ID. If the code does not resolve to exactly one record, it throws. The error message includes the offending parentCode value for debugging.","triggerScenarios":"A request to query tree children by code where parentCode references a non-existent code value — e.g., a typo in the code parameter, the referenced parent record was deleted, or the code field uses a different column than expected.","commonSituations":"Frontend tree component passes an old/deleted node's code; user manually types a code that doesn't exist; data migration changed codes but frontend cached old values; the parent-code field name differs from what the template assumed (pidFieldName mismatch).","solutions":["Verify the parentCode value exists in the database before calling queryListByCode.","If the parent was deleted, inform the user and refresh the tree from the root.","Ensure the code field column matches the entity's configured parent-code field name.","For optional/null parentCode, pass null or empty to start from the root (ROOT_PID_VALUE)."],"exampleFix":"// before — caller passes unvalidated code\nList<SelectTreeModel> tree = service.queryListByCode(userInputCode);  // throws\n// after — validate first\nif (oConvertUtils.isNotEmpty(userInputCode)) {\n    LambdaQueryWrapper<Entity> check = new LambdaQueryWrapper<>();\n    check.eq(Entity::getPid, userInputCode);\n    if (baseMapper.selectList(check).isEmpty()) {\n        return Result.error(\"Parent code not found: \" + userInputCode);\n    }\n}\nList<SelectTreeModel> tree = service.queryListByCode(userInputCode);","handlingStrategy":"validation","validationCode":"// Validate parentCode exists before querying tree\nif (oConvertUtils.isNotEmpty(parentCode)) {\n    LambdaQueryWrapper<Entity> check = new LambdaQueryWrapper<>();\n    check.eq(Entity::getPid, parentCode);\n    List<Entity> found = baseMapper.selectList(check);\n    if (found == null || found.isEmpty()) {\n        return Result.error(\"Parent code not found: \" + parentCode);\n    }\n}\nList<SelectTreeModel> tree = service.queryListByCode(parentCode);","typeGuard":"boolean parentCodeExists(BaseMapper<Entity> mapper, String parentCode) {\n    if (oConvertUtils.isEmpty(parentCode)) return true; // root query\n    LambdaQueryWrapper<Entity> qw = new LambdaQueryWrapper<>();\n    qw.eq(Entity::getPid, parentCode);\n    List<Entity> list = mapper.selectList(qw);\n    return list != null && list.size() == 1;\n}","tryCatchPattern":"try {\n    List<SelectTreeModel> tree = service.queryListByCode(parentCode);\n} catch (JeecgBootException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"不存在\")) {\n        return Result.error(\"The specified parent code does not exist: \" + parentCode);\n    }\n    throw e;\n}","preventionTips":["Validate the parentCode against the database before calling queryListByCode.","Pass null or empty parentCode to query from the root when appropriate.","Refresh tree node data after structural changes to avoid stale codes.","Ensure the pid field name in the template matches the actual entity column."],"tags":["jeecg-boot","crud","template","tree","runtime","generated-code","query"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}