{"record":{"id":"9f5699e6aa630d65","repo":"hibernate/hibernate-orm","slug":"sortspecification-is-missing-selection-indexes","errorCode":null,"errorMessage":"SortSpecification is missing selection indexes","messagePattern":"SortSpecification is missing selection indexes","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/sql/ast/spi/FullJoinEmulation.java","lineNumber":670,"sourceCode":"\t\t\tSortSpecification sortSpecification,\n\t\t\tNulls nullPrecedence,\n\t\t\tint selectItemCount,\n\t\t\tList<Expression> extraSelections,\n\t\t\tIdentityHashMap<SortSpecification, int[]> nullPrecedenceSelectionIndexes) {\n\t\tfinal var expressions = getSortExpressions( sortSpecification );\n\t\tfinal int[] indexes = new int[expressions.size()];\n\t\tfor ( int i = 0; i < expressions.size(); i++ ) {\n\t\t\textraSelections.add( createSortNullPrecedenceEmulationExpression( expressions.get( i ), nullPrecedence ) );\n\t\t\tindexes[i] = selectItemCount + extraSelections.size() - 1;\n\t\t}\n\t\tnullPrecedenceSelectionIndexes.put( sortSpecification, indexes );\n\t}\n\n\tprivate List<? extends Expression> getSortExpressions(SortSpecification sortSpecification) {\n\t\tfinal var sortExpression = sortSpecification.getSortExpression();\n\t\tfinal int[] sortSelectionIndexes = sortSpecification.getSortSelectionIndexes();\n\t\tif ( sortSelectionIndexes == null ) {\n\t\t\tthrow new IllegalStateException( \"SortSpecification is missing selection indexes\" );\n\t\t}\n\t\tfinal var tuple = getSqlTuple( sortExpression );\n\t\tfinal var expressions = tuple == null ? List.of( sortExpression ) : tuple.getExpressions();\n\t\tif ( sortSelectionIndexes.length != expressions.size() ) {\n\t\t\tthrow new IllegalStateException( \"SortSpecification selection indexes size mismatch\" );\n\t\t}\n\t\treturn expressions;\n\t}\n\n\tprivate Nulls resolveRenderedNullPrecedence(SortSpecification sortSpecification) {\n\t\tfinal var sortOrder = sortSpecification.getSortOrder();\n\t\tNulls nullPrecedence = sortSpecification.getNullPrecedence();\n\t\tif ( nullPrecedence == null || nullPrecedence == Nulls.NONE ) {\n\t\t\tnullPrecedence =\n\t\t\t\t\ttranslator.getSessionFactory().getSessionFactoryOptions()\n\t\t\t\t\t\t\t.getDefaultNullPrecedence();\n\t\t}\n\t\tif ( isDefaultOrdering( nullPrecedence, sortOrder,","sourceCodeStart":652,"sourceCodeEnd":688,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/FullJoinEmulation.java#L652-L688","documentation":"Error \"SortSpecification is missing selection indexes\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Hibernate builds a full-join emulation and the SortSpecification carries no selection indexes.","commonSituations":"ORDER BY on a full join on a dialect without native full-join support (e.g. older MySQL/MariaDB), where the sort keys could not be matched to select-list columns.","solutions":["This is an internal Hibernate assertion indicating the SortSpecification was built without selection indexes. If you see this error, report it as a Hibernate bug with the full stack trace and the query that triggered it.","As a workaround, simplify the ORDER BY clause or the query structure (e.g. remove the emulation of full joins) so the query takes a different code path."],"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"}