{"record":{"id":"dc92c6c344b3ce19","repo":"hibernate/hibernate-orm","slug":"full-join-emulation-requires-order-by-expressions-dc92c6","errorCode":null,"errorMessage":"Full join emulation requires order by expressions to be in the select list for union queries","messagePattern":"Full join emulation requires order by expressions to be in the select list for union queries","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/sql/ast/spi/FullJoinEmulation.java","lineNumber":539,"sourceCode":"\t\t\ttranslator.appendSql( separator );\n\t\t\trenderFullJoinEmulationSortExpression(\n\t\t\t\t\tsortSpecification,\n\t\t\t\t\tsortSelectionIndexes[i],\n\t\t\t\t\tnullPrecedenceSelectionIndexes == null ? -1 : nullPrecedenceSelectionIndexes[i]\n\t\t\t);\n\t\t\tseparator = COMMA_SEPARATOR;\n\t\t}\n\t}\n\n\tprivate void renderFullJoinEmulationSortExpression(\n\t\t\tSortSpecification sortSpecification,\n\t\t\tint sortSelectionIndex,\n\t\t\tint nullPrecedenceSelectionIndex) {\n\t\tif ( sortSpecification.isIgnoreCase() ) {\n\t\t\tthrow new UnsupportedOperationException( \"Full join emulation does not support ignore case ordering for union queries\" );\n\t\t}\n\t\tif ( sortSelectionIndex < 0 ) {\n\t\t\tthrow new UnsupportedOperationException( \"Full join emulation requires order by expressions to be in the select list for union queries\" );\n\t\t}\n\n\t\tfinal var sortOrder = sortSpecification.getSortOrder();\n\t\tfinal var nullPrecedence = resolveRenderedNullPrecedence( sortSpecification );\n\t\tfinal boolean renderNullPrecedence = nullPrecedence != null;\n\t\tfinal boolean supportsNullPrecedence = renderNullPrecedence && translator.getDialect().supportsNullPrecedence();\n\t\tif ( renderNullPrecedence && !supportsNullPrecedence ) {\n\t\t\tif ( nullPrecedenceSelectionIndex < 0 ) {\n\t\t\t\tthrow new IllegalStateException( \"Full join emulation null precedence index is missing for union query ordering\" );\n\t\t\t}\n\t\t\ttranslator.appendSql( nullPrecedenceSelectionIndex + 1 );\n\t\t\ttranslator.appendSql( COMMA_SEPARATOR );\n\t\t}\n\n\t\ttranslator.appendSql( sortSelectionIndex + 1 );\n\n\t\tif ( sortOrder == SortDirection.DESCENDING ) {\n\t\t\ttranslator.appendSql( \" desc\" );","sourceCodeStart":521,"sourceCodeEnd":557,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/FullJoinEmulation.java#L521-L557","documentation":"Error \"Full join emulation requires order by expressions to be in the select list for union queries\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Full join emulation on a union query requires every ORDER BY expression to appear in the select list, and one is missing.","commonSituations":"Ordering a UNION by a column not selected; add the order expression to the select list.","solutions":["Add every ORDER BY expression to the select list of each union query part.","Alternatively order by select-item position or alias instead of by raw expression.","Remove ORDER BY items that cannot be added to the select list."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}