hs-web/hsweb-framework · error · IllegalStateException

table " + table + " not found in from or join

Error message

table " + table + " not found in from or join

What it means

getTable resolves a JSqlParser table reference to analyzer metadata: it first matches the FROM-table alias, then looks up the joins map. If the table name is neither the FROM alias nor a registered join, an IllegalStateException is thrown because the analyzer cannot bind columns of that table.

Solutions

  1. Add the missing `JOIN <table> <alias>` clause for the referenced table.
  2. Use the FROM-table alias instead of the real table name when qualifying columns.
  3. Verify the table exists in the database metadata/schema the analyzer was built with.

Example fix

// before
"select u2.name from user u"
// after
"select u.name from user u" // or add: join user2 u2 on ...
Defensive patterns

Strategy: validation

Validate before calling

if (!fromAlias.equals(qualifier) && !joinAliases.contains(qualifier)) { throw new IllegalArgumentException("qualifier " + qualifier + " must be the FROM alias or a joined alias"); }

Try / catch

try { analyzer.analyze(dql); } catch (IllegalStateException e) { if (e.getMessage().contains("not found in from or join")) { /* suggest adding JOIN */ } throw e; }

Prevention

When it happens

Trigger: A column qualifier or subquery FROM reference names a table/alias that is not the main FROM alias and was never joined, e.g. `select other.col from main_table` where `other` has no JOIN entry; triggered from getTable via the column visiting path.

Common situations: Queries referencing a table by its real name instead of its declared alias; missing join clauses in dynamically composed SQL; queries against tables not registered in the current database metadata.

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/83fcbdf972464576. Report an issue: GitHub.

Appendix: source

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

        if (join == null) {
            throw new IllegalStateException("table " + table.getName() + " not found in join");
        }
        putSelectColumns(join.table, select.columnList);
    }

    private QueryAnalyzer.Table getTable(net.sf.jsqlparser.schema.Table table) {
        QueryAnalyzer.Table meta;
        if (null == table) {
            return select.table;
        }
        String tableName = parsePlainName(table.getName());

        if (Objects.equals(tableName, select.table.alias)) {
            meta = select.table;
        } else {
            QueryAnalyzer.Join join = joins.get(tableName);
            if (join == null) {
                throw new IllegalStateException("table " + table + " not found in from or join");
            }
            meta = join.table;
        }
        return meta;
    }


    static class ExpressionColumn extends Column {

        private final SelectItem expr;

        public ExpressionColumn(String alias, String owner, RDBColumnMetadata metadata, SelectItem expr) {
            super(alias, alias, owner, metadata);
            this.expr = expr;
        }

        @Override
        public ExpressionColumn moveOwner(String owner) {

View on GitHub (pinned to b2cfc85a57)