{"record":{"id":"17042f21608fe50c","repo":"hibernate/hibernate-orm","slug":"can-t-emulate-join-in-a-db2-recursive-query-pa","errorCode":null,"errorMessage":"Can't emulate '{}join' in a DB2 recursive query part","messagePattern":"Can't emulate '(.+?)join' in a DB2 recursive query part","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/dialect/sql/ast/DB2SqlAstTranslator.java","lineNumber":91,"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 );\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":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/dialect/sql/ast/DB2SqlAstTranslator.java#L73-L109","documentation":"Rendering a query inside a recursive CTE on DB2 encountered joins on the table reference; DB2 (error SQL0345) does not allow joins in the recursive member of a WITH query. The query must be restructured to avoid joins within the recursive part when targeting DB2.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/dialect/sql/ast/DB2SqlAstTranslator.java:91 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Restructure the recursive query so the join does not appear inside the recursive part on DB2","Move the joined table out of the recursive CTE and join it in the outer query"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}