{"record":{"id":"4fc4aa5c23ad8185","repo":"hs-web/hsweb-framework","slug":"column-column-getcolumnname-not-found-in-table-metadata","errorCode":null,"errorMessage":"column [\" + column.getColumnName() + \"] not found in \" + table.metadata.getName()","messagePattern":"column \\[\" \\+ column\\.getColumnName\\(\\) \\+ \"\\] not found in \" \\+ table\\.metadata\\.getName\\(\\)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/query/QueryAnalyzerImpl.java","lineNumber":553,"sourceCode":"            .getMetadata()\n            .getColumn(columnName)\n            .orElse(null);\n\n        if (metadata == null) {\n            if (table instanceof QueryAnalyzer.SelectTable) {\n                Column c = ((SelectTable) table).columns.get(columnName);\n                if (null != c) {\n                    if (c.metadata == null) {\n                        select.columnList.add(new QueryAnalyzer.Column(c.getName(), aliasName, table.alias, null));\n                        return;\n                    }\n                    metadata = c.metadata;\n                }\n            }\n        }\n\n        if (metadata == null) {\n            throw new IllegalStateException(\"column [\" + column.getColumnName() + \"] not found in \" + table.metadata.getName());\n        }\n\n        select.columnList.add(new QueryAnalyzer.Column(metadata.getRealName(), aliasName, table.alias, metadata));\n\n\n    }\n\n    @Override\n    public void visit(PlainSelect select) {\n\n        FromItem from = select.getFromItem();\n\n        if (from == null) {\n            throw new IllegalArgumentException(\"select can not be without 'from'\");\n        }\n        from.accept(this);\n\n","sourceCodeStart":535,"sourceCodeEnd":571,"githubUrl":"https://github.com/hs-web/hsweb-framework/blob/b2cfc85a57c70bf5b5cf6e7edae2d37102652ec8/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/query/QueryAnalyzerImpl.java#L535-L571","documentation":"After resolving the owning table metadata for a selected column, the analyzer searches the table's metadata for a matching RDBColumnMetadata. If none is found (the column is not defined on that table/view), an IllegalStateException is thrown naming the column and the table metadata name, because result columns must map to real or virtual column metadata.","triggerScenarios":"Selecting a column that does not exist on the resolved table, e.g. `select t.unknown_field from table t` where `unknown_field` is absent from the entity/table metadata; also happens when select * expansion resolves a column against the wrong joined table.","commonSituations":"Renamed or dropped entity fields without updating queries; typos in column names; queries built against tables whose metadata (columns) were not registered with the RDBDatabaseMetadata.","solutions":["Correct the column name to one defined on the table metadata.","Register the missing column in the table/entity metadata (RDBTableMetadata.addColumn).","If the column comes from another table, qualify it with the correct join alias."],"exampleFix":"// before\n\"select u.nmae from s_user u\"\n// after\n\"select u.name from s_user u\"","handlingStrategy":"validation","validationCode":"boolean exists = tableMetadata.getColumn(columnName).isPresent(); if (!exists) { throw new IllegalArgumentException(\"column \" + columnName + \" is not defined on \" + tableMetadata.getName()); }","typeGuard":null,"tryCatchPattern":"try { analyzer.analyze(dql); } catch (IllegalStateException e) { if (e.getMessage().startsWith(\"column [\")) { /* map to 400 with the column name */ } throw e; }","preventionTips":["Keep entity field names and table metadata in sync after renames","Use constants/constants classes for column names instead of raw strings","Cover every dynamic SELECT with a metadata-aware test"],"tags":["sql","column-not-found","metadata","query-analyzer"],"backgroundTag":"resource-not-found","analyzedSha":"b2cfc85a57c70bf5b5cf6e7edae2d37102652ec8","analyzedAt":"2026-09-13T09:05:02.172Z","contentChangedAt":"2026-09-13T09:05:02.172Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}