{"record":{"id":"e46c049846adbe4b","repo":"hibernate/hibernate-orm","slug":"full-join-emulation-null-precedence-index-is-missi","errorCode":null,"errorMessage":"Full join emulation null precedence index is missing for union query ordering","messagePattern":"Full join emulation null precedence index is missing for union query ordering","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/sql/ast/spi/FullJoinEmulation.java","lineNumber":548,"sourceCode":"\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\" );\n\t\t}\n\t\telse if ( sortOrder == SortDirection.ASCENDING && renderNullPrecedence && supportsNullPrecedence ) {\n\t\t\ttranslator.appendSql( \" asc\" );\n\t\t}\n\n\t\tif ( renderNullPrecedence && supportsNullPrecedence ) {\n\t\t\ttranslator.appendSql( \" nulls \" );\n\t\t\ttranslator.appendSql( nullPrecedence == Nulls.LAST ? \"last\" : \"first\" );\n\t\t}","sourceCodeStart":530,"sourceCodeEnd":566,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/FullJoinEmulation.java#L530-L566","documentation":"Error \"Full join emulation null precedence index is missing for union query ordering\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Full join emulation builds union ordering but the null-precedence index mapping for an order item is absent.","commonSituations":"Explicit NULLS FIRST/LAST on a union full join where the emulation could not map the precedence; remove explicit null precedence.","solutions":["Avoid explicit NULLS FIRST/NULLS LAST in the ORDER BY of a union query that requires full join emulation.","If null precedence is required, express it with a CASE expression in the select list and order by that item.","Use a database/dialect with native FULL JOIN support so the emulation path (and this limitation) is not used."],"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"}