{"record":{"id":"e4de4a95c4acaace","repo":"hibernate/hibernate-orm","slug":"can-t-emulate-tablejoin-getjointype-gettext","errorCode":null,"errorMessage":"Can't emulate '\" + tableJoin.getJoinType().getText() + \"join' in a DB2 recursive query part","messagePattern":"Can't emulate '\" \\+ tableJoin\\.getJoinType\\(\\)\\.getText\\(\\) \\+ \"join' in a DB2 recursive query part","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2LegacySqlAstTranslator.java","lineNumber":93,"sourceCode":"\t}\n\n\t@Override\n\tprotected void renderTableReferenceJoins(TableGroup tableGroup, LockMode lockMode, int swappedJoinIndex, boolean forceLeftJoin) {\n\t\t// When we are in a recursive CTE, we can't render joins on DB2...\n\t\t// See https://modern-sql.com/feature/with-recursive/db2/error-345-state-42836\n\t\tif ( isInRecursiveQueryPart() ) {\n\t\t\tfinal List<TableReferenceJoin> joins = tableGroup.getTableReferenceJoins();\n\t\t\tif ( joins == null || joins.isEmpty() ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tfor ( TableReferenceJoin tableJoin : joins ) {\n\t\t\t\tswitch ( tableJoin.getJoinType() ) {\n\t\t\t\t\tcase CROSS:\n\t\t\t\t\tcase INNER:\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new UnsupportedOperationException( \"Can't emulate '\" + tableJoin.getJoinType().getText() + \"join' in a DB2 recursive query part\" );\n\t\t\t\t}\n\t\t\t\tappendSql( COMMA_SEPARATOR_CHAR );\n\n\t\t\t\trenderNamedTableReference( tableJoin.getJoinedTableReference(), LockMode.NONE );\n\n\t\t\t\tif ( tableJoin.getPredicate() != null && !tableJoin.getPredicate().isEmpty() ) {\n\t\t\t\t\taddAdditionalWherePredicate( tableJoin.getPredicate() );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tsuper.renderTableReferenceJoins( tableGroup, lockMode, swappedJoinIndex, forceLeftJoin );\n\t\t}\n\t}\n\n\t@Override\n\tprotected void renderTableGroupJoin(TableGroupJoin tableGroupJoin, List<TableGroupJoin> tableGroupJoinCollector) {\n\t\tif ( isInRecursiveQueryPart() ) {","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2LegacySqlAstTranslator.java#L75-L111","documentation":"NamedTableReference is the from-element for one concrete named table; resolveTableReference returns itself only when the requested expression equals its own tableExpression and throws UnknownTableReferenceException otherwise. Hitting it means the resolver asked a single-table reference for a different table's name - usually a secondary or subclass table being resolved against the primary table reference instead of the enclosing table group.","triggerScenarios":"Resolving a secondary-table column (@SecondaryTable/@SecondaryTables) or a subclass table directly on the primary NamedTableReference instead of through the TableGroup; join pruning or custom translators resolving columns at reference level; mapping changes where a column's table no longer matches the reference.","commonSituations":"Entities with secondary tables after remapping columns between primary and secondary; custom SqlAstTranslator extensions resolving columns via table references; upgrades tightening reference-level vs group-level resolution.","solutions":["Resolve through the TableGroup (group.resolveTableReference(...)) rather than a single NamedTableReference when secondary/subclass tables may be involved.","Verify the attribute's mapped table matches the mapping (column listed under the right table/@SecondaryTable) after schema refactors.","Ensure secondary-table joins are not pruned when their columns are selected.","Upgrade Hibernate; report if core code resolves at the wrong level."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    return query.getResultList();\n} catch ( UnknownTableReferenceException e ) {\n    // secondary/subclass table resolved against the primary reference: fix the mapping or query the right group\n    LOG.error(\"Table {} not on primary reference - check @SecondaryTable mapping for {}\", e.getTableExpression(), entity);\n    throw e;\n}","preventionTips":["In custom translators, resolve columns via TableGroup.resolveTableReference(...) (group-level) rather than individual NamedTableReference instances.","After moving columns between primary and secondary tables, re-run all named queries to revalidate resolution.","Ensure secondary-table joins are not pruned when secondary columns appear in select/order-by."],"tags":["table-reference","named-table","secondary-table","sql-ast","mapping"],"backgroundTag":"unknown-table-reference","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}