{"record":{"id":"83fcbdf972464576","repo":"hs-web/hsweb-framework","slug":"table-table-not-found-in-from-or-join","errorCode":null,"errorMessage":"table \" + table + \" not found in from or join","messagePattern":"table \" \\+ table \\+ \" not found in from or 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":481,"sourceCode":"        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            }\n            meta = join.table;\n        }\n        return meta;\n    }\n\n\n    static class ExpressionColumn extends Column {\n\n        private final SelectItem expr;\n\n        public ExpressionColumn(String alias, String owner, RDBColumnMetadata metadata, SelectItem expr) {\n            super(alias, alias, owner, metadata);\n            this.expr = expr;\n        }\n\n        @Override\n        public ExpressionColumn moveOwner(String owner) {","sourceCodeStart":463,"sourceCodeEnd":499,"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#L463-L499","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add the missing `JOIN <table> <alias>` clause for the referenced table.","Use the FROM-table alias instead of the real table name when qualifying columns.","Verify the table exists in the database metadata/schema the analyzer was built with."],"exampleFix":"// before\n\"select u2.name from user u\"\n// after\n\"select u.name from user u\" // or add: join user2 u2 on ...","handlingStrategy":"validation","validationCode":"if (!fromAlias.equals(qualifier) && !joinAliases.contains(qualifier)) { throw new IllegalArgumentException(\"qualifier \" + qualifier + \" must be the FROM alias or a joined alias\"); }","typeGuard":null,"tryCatchPattern":"try { analyzer.analyze(dql); } catch (IllegalStateException e) { if (e.getMessage().contains(\"not found in from or join\")) { /* suggest adding JOIN */ } throw e; }","preventionTips":["Qualify columns with the FROM alias, not the real table name","Add JOINs before referencing their tables","Keep database metadata registered for all referenced tables"],"tags":["sql","join","table-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"}