{"record":{"id":"b449a7913979ec27","repo":"hibernate/hibernate-orm","slug":"select-item-was-not-an-entity-type","errorCode":null,"errorMessage":"Select item was not an entity type","messagePattern":"Select item was not an entity type","errorType":"exception","errorClass":"IllegalQueryOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/internal/KeyBasedPagination.java","lineNumber":66,"sourceCode":"\t\t\t\t}\n\t\t\t\tyield sqmRoots.get( 0 );\n\t\t\t}\n\t\t\tcase 1 -> items.get( 0 );\n\t\t\tdefault -> throw new IllegalQueryOperationException(\"Query has multiple items in the select list\");\n\t\t};\n\t\tif ( selected instanceof SqmFrom<?, ?> root ) {\n\t\t\tstatement.orderBy( keyDefinition.stream().map( order -> sortSpecification( statement, order ) )\n\t\t\t\t\t.collect( toList() ) );\n\t\t\tstatement.select( keySelection( keyDefinition, root, selected, builder ) );\n\t\t\tif ( keyValues != null ) {\n\t\t\t\tfinal SqmPredicate restriction = keyRestriction( keyDefinition, keyValues, root, builder );\n\t\t\t\tfinal SqmPredicate queryWhere = querySpec.getRestriction();\n\t\t\t\tstatement.where( queryWhere == null ? restriction : builder.and( queryWhere, restriction ) );\n\t\t\t}\n\t\t\treturn statement;\n\t\t}\n\t\telse {\n\t\t\tthrow new IllegalQueryOperationException(\"Select item was not an entity type\");\n\t\t}\n\t}\n\n\t@SuppressWarnings({\"rawtypes\", \"unchecked\"})\n\tprivate static <R> SqmPredicate keyRestriction(\n\t\t\tList<Order<? super R>> keyDefinition,\n\t\t\tList<Comparable<?>> keyValues,\n\t\t\tSqmFrom<?, ?> root,\n\t\t\tNodeBuilder builder) {\n\t\tfinal List<SqmPath<?>> keyPaths = new ArrayList<>();\n\t\tfor ( Order<? super R> key : keyDefinition ) {\n\t\t\tkeyPaths.add( root.get( key.attributeName() ) );\n\t\t}\n\t\tSqmPredicate restriction = null;\n\t\tfor (int i = 0; i < keyDefinition.size(); i++ ) {\n\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);","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/internal/KeyBasedPagination.java#L48-L84","documentation":"Error \"Select item was not an entity type\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A name/path expected to denote an entity type does not: Select item was not an entity type","commonSituations":"Passing non-entity arguments to version()/naturalid(), or a TREAT target / entity name that is not a mapped entity; commonly a typo or unmapped class.","solutions":["The select item of a key-paginated query must be an entity. Select the entity itself rather than scalar attributes."],"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"}