jeecgboot/JeecgBoot · error · JeecgBootException

该编码【${parentCode}】存在多个,请核实!

Error message

该编码【${parentCode}】存在多个,请核实!

What it means

This is a FreeMarker code-generator template (note the `.javai` extension) that emits a `queryListByCode` service method for online tree-list entities. At runtime the generated method looks up the parent node by `parentCode` against the configured parent-id field `${pidFieldName}`; if that lookup returns MORE than one row it throws `JeecgBootException` because the parent code is ambiguous. The guard exists so the tree never silently picks an arbitrary parent.

Source

Thrown at 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:145

                    mapList.add(data);
                }
            }
        }
        return mapList;
    }

    @Override
    public List<SelectTreeModel> queryListByCode(String parentCode) {
        String pid = ROOT_PID_VALUE;
        if (oConvertUtils.isNotEmpty(parentCode)) {
            LambdaQueryWrapper<${entityName}> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(${entityName}::get${pidFieldName?cap_first}, parentCode);
            List<${entityName}> list = baseMapper.selectList(queryWrapper);
            if (list == null || list.size() == 0) {
                throw new JeecgBootException("该编码【" + parentCode + "】不存在,请核实!");
            }
            if (list.size() > 1) {
                throw new JeecgBootException("该编码【" + parentCode + "】存在多个,请核实!");
            }
            pid = list.get(0).getId();
        }
        return baseMapper.queryListByPid(pid, null);
    }

    @Override
    public List<SelectTreeModel> queryListByPid(String pid) {
        if (oConvertUtils.isEmpty(pid)) {
            pid = ROOT_PID_VALUE;
        }
        return baseMapper.queryListByPid(pid, null);
    }

	/**
	 * 根据所传pid查询旧的父级节点的子节点并修改相应状态值
	 * @param pid
	 */

View on GitHub (pinned to 96fb33f5ec)

Solutions

  1. Query the offending duplicates: `SELECT ${pidFieldName}, COUNT(*) FROM <table> WHERE ${pidFieldName} = '<parentCode>' GROUP BY ${pidFieldName}` and merge/delete the extras.
  2. Confirm the cgform tree config uses a genuinely unique parent-code field, not a display name.
  3. Add a unique DB index on the parent-code column to block future ambiguity.
  4. If duplicates are legitimate, change the lookup to disambiguate with a second column instead of relying on `parentCode` alone.

Example fix

// before
queryWrapper.eq(${entityName}::get${pidFieldName?cap_first}, parentCode);
List<${entityName}> list = baseMapper.selectList(queryWrapper);
if (list.size() > 1) { throw new JeecgBootException("该编码【" + parentCode + "】存在多个,请核实!"); }

// after — narrow with an extra discriminator + keep the guard as a safety net
queryWrapper.eq(${entityName}::get${pidFieldName?cap_first}, parentCode)
            .eq(${entityName}::getTenantId, TenantContext.getTenantId())
            .last("LIMIT 1");
Defensive patterns

Strategy: validation

Validate before calling

// before calling queryListByCode, verify the parent code is unique
long count = baseMapper.selectCount(new LambdaQueryWrapper<${entityName}>()
    .eq(${entityName}::get${pidFieldName?cap_first}, parentCode));
if (count > 1) {
    // surface duplicates to the user / pick a different code; do NOT call queryListByCode
}

Try / catch

// at the controller boundary — JeecgBootException is a business exception
try {
    return Result.OK(service.queryListByCode(parentCode));
} catch (JeecgBootException e) {
    return Result.error(e.getMessage());
}

Prevention

When it happens

Trigger: Calling the generated `queryListByCode(parentCode)` with a non-empty `parentCode` whose value occurs in MORE than one row of the `${pidFieldName}` column (e.g. two records share `parent_code = 'A01'`). Only fires when `parentCode` is non-empty; an empty/null `parentCode` falls back to `ROOT_PID_VALUE` and never throws.

Common situations: Seed/import data loaded duplicate parent codes; the cgform tree settings point `pidFieldName` at a non-unique display column (a name) instead of a true code; rows were hand-edited to repeat a code; a unique index was never created on the parent-code column.

Related errors


AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14). Data as JSON: /api/errors/0f3939023082652c. Report an issue: GitHub.