hs-web/hsweb-framework · error · IllegalStateException

column [" + column.getColumnName() + "] not found in " +…

Error message

column [" + column.getColumnName() + "] not found in " + table.metadata.getName()

What it means

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.

Solutions

  1. Correct the column name to one defined on the table metadata.
  2. Register the missing column in the table/entity metadata (RDBTableMetadata.addColumn).
  3. If the column comes from another table, qualify it with the correct join alias.

Example fix

// before
"select u.nmae from s_user u"
// after
"select u.name from s_user u"
Defensive patterns

Strategy: validation

Validate before calling

boolean exists = tableMetadata.getColumn(columnName).isPresent(); if (!exists) { throw new IllegalArgumentException("column " + columnName + " is not defined on " + tableMetadata.getName()); }

Try / catch

try { analyzer.analyze(dql); } catch (IllegalStateException e) { if (e.getMessage().startsWith("column [")) { /* map to 400 with the column name */ } throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of hs-web/hsweb-framework@b2cfc85a57 (2026-09-13). Data as JSON: /api/errors/4fc4aa5c23ad8185. Report an issue: GitHub.

Appendix: source

Thrown at hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/query/QueryAnalyzerImpl.java:553

            .getMetadata()
            .getColumn(columnName)
            .orElse(null);

        if (metadata == null) {
            if (table instanceof QueryAnalyzer.SelectTable) {
                Column c = ((SelectTable) table).columns.get(columnName);
                if (null != c) {
                    if (c.metadata == null) {
                        select.columnList.add(new QueryAnalyzer.Column(c.getName(), aliasName, table.alias, null));
                        return;
                    }
                    metadata = c.metadata;
                }
            }
        }

        if (metadata == null) {
            throw new IllegalStateException("column [" + column.getColumnName() + "] not found in " + table.metadata.getName());
        }

        select.columnList.add(new QueryAnalyzer.Column(metadata.getRealName(), aliasName, table.alias, metadata));


    }

    @Override
    public void visit(PlainSelect select) {

        FromItem from = select.getFromItem();

        if (from == null) {
            throw new IllegalArgumentException("select can not be without 'from'");
        }
        from.accept(this);

View on GitHub (pinned to b2cfc85a57)