{"record":{"id":"910a7ecc7db13025","repo":"baomidou/mybatis-plus","slug":"error-910a7e","errorCode":null,"errorMessage":"获取自定义字段错误:","messagePattern":"获取自定义字段错误:","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/querys/DbQueryDecorator.java","lineNumber":185,"sourceCode":"    @Override\n    public String[] fieldCustom() {\n        return dbQuery.fieldCustom();\n    }\n\n    @Override\n    public String primaryKeySql(DataSourceConfig dataSourceConfig, String tableName) {\n        return dbQuery.primaryKeySql(dataSourceConfig, tableName);\n    }\n\n    public Map<String, Object> getCustomFields(ResultSet resultSet) {\n        String[] fcs = this.fieldCustom();\n        if (null != fcs) {\n            Map<String, Object> customMap = CollectionUtils.newHashMapWithExpectedSize(fcs.length);\n            for (String fc : fcs) {\n                try {\n                    customMap.put(fc, resultSet.getObject(fc));\n                } catch (SQLException sqlException) {\n                    throw new RuntimeException(\"获取自定义字段错误:\", sqlException);\n                }\n            }\n            return customMap;\n        }\n        return Collections.emptyMap();\n    }\n\n    /**\n     * 执行 SQL 查询，回调返回结果\n     *\n     * @param sql      执行SQL\n     * @param consumer 结果处理\n     */\n    public void execute(String sql, Consumer<ResultSetWrapper> consumer) throws SQLException {\n        logger.debug(\"执行SQL:{}\", sql);\n        int count = 0;\n        long start = System.nanoTime();\n        try (PreparedStatement preparedStatement = connection.prepareStatement(sql);","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/baomidou/mybatis-plus/blob/bf67d907478c724120bf76292da54abf9e73c2b3/mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/querys/DbQueryDecorator.java#L167-L203","documentation":"DbQueryDecorator.getCustomFields wraps a SQLException in a RuntimeException while reading each custom field (from fieldCustom()) out of the table-metadata ResultSet. It fires when the underlying JDBC driver cannot resolve a column name the dbQuery implementation declared, so resultSet.getObject(fc) throws.","triggerScenarios":"Using a DbType whose IDbQuery implementation declares fieldCustom() columns that the actual query/ResultSet does not return — typically after a driver/dbms version change where metadata column names differ, or when a custom IDbQuery is registered with misspelled field names.","commonSituations":"ClickHouse/DM/Kingbase and other less-common DbType query adapters whose fieldCustom() list drifts from what the shipped SQL selects; using an older JDBC driver whose metadata result lacks a column (e.g. REMARKS variants) the adapter expects.","solutions":["Check the SQLException cause in the stack trace: 'column not found' identifies exactly which fieldCustom() entry is wrong for your driver.","Upgrade mybatis-plus-generator to a version whose query adapter matches your database/driver version.","If using a custom IDbQuery, align fieldCustom() with the columns actually produced by your tablesSql().","As a workaround, supply a DataSourceConfig with a SchemaDataSource query override that removes the failing custom field."],"exampleFix":"// before (custom adapter declares a column the ResultSet lacks)\n@Override\npublic String[] fieldCustom() {\n    return new String[]{\" remarks_bad_name\"};\n}\n\n// after\n@Override\npublic String[] fieldCustom() {\n    return new String[]{\"REMARKS\"};\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    generator.generate();\n} catch (RuntimeException e) {\n    if (e.getCause() instanceof SQLException sqlEx) {\n        // identify failing fieldCustom column from sqlEx message; fix IDbQuery/driver version\n        log.error(\"custom field metadata read failed: {}\", sqlEx.getMessage(), e);\n    }\n}","preventionTips":["Let DataSourceConfig auto-detect DbType from the URL instead of forcing a dbQuery.","Keep the JDBC driver version aligned with the mybatis-plus-generator version's tested adapters.","For custom IDbQuery implementations, add an integration test that runs getCustomFields against the real database."],"tags":["mybatis-plus","code-generator","jdbc","metadata","custom-fields"],"backgroundTag":null,"analyzedSha":"bf67d907478c724120bf76292da54abf9e73c2b3","analyzedAt":"2026-08-14T15:17:09.543Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}