{"record":{"id":"d180792350f81598","repo":"hs-web/hsweb-framework","slug":"table-table-getname-not-found-in-join","errorCode":null,"errorMessage":"table \" + table.getName() + \" not found in join","messagePattern":"table \" \\+ table\\.getName\\(\\) \\+ \" not found in join","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":464,"sourceCode":"            }\n        }\n    }\n\n    @Override\n    public void visit(AllTableColumns allTableColumns) {\n        net.sf.jsqlparser.schema.Table table = allTableColumns.getTable();\n\n        String name = table.getName();\n\n        if (Objects.equals(select.table.alias, name)) {\n            putSelectColumns(select.table, select.columnList);\n            return;\n        }\n\n        QueryAnalyzer.Join join = joins.get(parsePlainName(table.getName()));\n\n        if (join == null) {\n            throw new IllegalStateException(\"table \" + table.getName() + \" not found in join\");\n        }\n        putSelectColumns(join.table, select.columnList);\n    }\n\n    private QueryAnalyzer.Table getTable(net.sf.jsqlparser.schema.Table table) {\n        QueryAnalyzer.Table meta;\n        if (null == table) {\n            return select.table;\n        }\n        String tableName = parsePlainName(table.getName());\n\n        if (Objects.equals(tableName, select.table.alias)) {\n            meta = select.table;\n        } else {\n            QueryAnalyzer.Join join = joins.get(tableName);\n            if (join == null) {\n                throw new IllegalStateException(\"table \" + table + \" not found in from or join\");\n            }","sourceCodeStart":446,"sourceCodeEnd":482,"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#L446-L482","documentation":"During column visiting, the analyzer maps a column's table alias to a previously registered join via `joins.get(alias)`. When an alias referenced in the SELECT list was never registered by a JOIN clause, the lookup returns null and an IllegalStateException is thrown, indicating the query references a table that is not part of the FROM/JOIN structure the analyzer built.","triggerScenarios":"Running an analyzed query whose SELECT list qualifies a column with an alias (`t1.name`) that appears neither in FROM nor in any JOIN clause, or where the join alias differs (case/`parsePlainName` stripping) from the qualifier used.","commonSituations":"Copy-pasted SQL with leftover aliases after removing a JOIN; dynamically assembled query builders emitting stale aliases; aliases created via quoted or backtick-quoted identifiers that parsePlainName strips differently.","solutions":["Ensure every alias used to qualify columns has a corresponding `JOIN table alias` clause in the query.","Remove or correct the stale alias in the SELECT list.","Check alias quoting: use the same spelling (no extra quotes/backticks) in the JOIN and in column qualifiers."],"exampleFix":"// before\n\"select t2.name from user t1\"\n// after\n\"select t2.name from user t1 join role t2 on t1.id = t2.user_id\"","handlingStrategy":"validation","validationCode":"Set<String> aliases = extractJoinAliases(sql); for (String q : extractColumnQualifiers(sql)) { if (!aliases.contains(q) && !q.equals(fromAlias)) { throw new IllegalArgumentException(\"unknown alias: \" + q); } }","typeGuard":null,"tryCatchPattern":"try { analyzer.analyze(dql); } catch (IllegalStateException e) { if (e.getMessage().contains(\"not found in join\")) { log.warn(\"stale alias in query: {}\", e.getMessage()); } throw e; }","preventionTips":["Keep SELECT qualifiers in sync with JOIN clauses","Search codebase for removed joins after refactoring SQL","Use the same alias spelling everywhere (no mixed quoting)"],"tags":["sql","join","alias-not-found","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"}