{"record":{"id":"e104f7109bc4d055","repo":"hibernate/hibernate-orm","slug":"key-based-pagination-based-on-select-list-items-is","errorCode":null,"errorMessage":"Key-based pagination based on select list items is not yet supported","messagePattern":"Key-based pagination based on select list items is not yet supported","errorType":"exception","errorClass":"IllegalQueryOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/internal/KeyBasedPagination.java","lineNumber":100,"sourceCode":"\t\t\t// ordering by an attribute of the returned entity\n\t\t\tfinal SortDirection direction = keyDefinition.get(i).direction();\n\t\t\tfinal SqmPath key = keyPaths.get(i);\n\t\t\tfinal Comparable keyValue = keyValues.get(i);\n\t\t\tfinal List<SqmPath<?>> previousKeys = keyPaths.subList(0, i);\n\t\t\tfinal SqmPredicate predicate = keyPredicate( key, keyValue, direction, previousKeys, keyValues, builder );\n\t\t\trestriction = restriction == null ? predicate : builder.or( restriction, predicate );\n\t\t}\n\t\treturn restriction;\n\t}\n\n\tprivate static <R> JpaCompoundSelection<KeyedResult<R>> keySelection(\n\t\t\tList<Order<? super R>> keyDefinition,\n\t\t\tSqmFrom<?, ?> root, JpaSelection<?> selected,\n\t\t\tNodeBuilder builder) {\n\t\tfinal List<SqmPath<?>> items = new ArrayList<>();\n\t\tfor ( Order<? super R> key : keyDefinition ) {\n\t\t\tif ( key.entityClass() == null ) {\n\t\t\t\tthrow new IllegalQueryOperationException(\"Key-based pagination based on select list items is not yet supported\");\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif ( !key.entityClass().isAssignableFrom( selected.getJavaType() ) ) {\n\t\t\t\t\tthrow new IllegalQueryOperationException(\"Select item was of wrong entity type\");\n\t\t\t\t}\n\t\t\t\t// ordering by an attribute of the returned entity\n\t\t\t\titems.add( root.get( key.attributeName() ) );\n\t\t\t}\n\t\t}\n\t\treturn keyedResultConstructor( selected, builder, items );\n\t}\n\n\tprivate static <R> JpaCompoundSelection<KeyedResult<R>> keyedResultConstructor(\n\t\t\tJpaSelection<?> selected, NodeBuilder builder, List<SqmPath<?>> newItems) {\n\t\t@SuppressWarnings({\"rawtypes\", \"unchecked\"})\n\t\tfinal Class<KeyedResult<R>> resultClass = (Class) KeyedResult.class;\n\t\treturn builder.construct( resultClass, asList( selected, builder.construct(List.class, newItems ) ) );\n\t}","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/internal/KeyBasedPagination.java#L82-L118","documentation":"Error \"Key-based pagination based on select list items is not yet supported\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Key-based pagination preconditions are not met: Key-based pagination based on select list items is not yet supported","commonSituations":"Using key-based pagination on queries with no/multiple roots, multi-item select lists, non-entity select items, or pages containing null key values.","solutions":["Pagination over select-list items is not supported. Page over the entity root instead."],"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"}