{"record":{"id":"870e91ddcc01d89f","repo":"hibernate/hibernate-orm","slug":"expecting-a-selection-query-but-found-870e91","errorCode":null,"errorMessage":"Expecting a selection query, but found '{}'","messagePattern":"Expecting a selection query, but found '(.+?)'","errorType":"exception","errorClass":"IllegalSelectQueryException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/specification/internal/SelectionSpecificationImpl.java","lineNumber":346,"sourceCode":"\t */\n\t@Nonnull\n\tprivate static <T> SqmSelectStatement<T> resolveSqmTree(\n\t\t\t@Nonnull String hql,\n\t\t\t@Nonnull Class<T> resultType,\n\t\t\t@Nonnull QueryEngine queryEngine) {\n\t\tfinal var hqlInterpretation =\n\t\t\t\tqueryEngine.getInterpretationCache()\n\t\t\t\t\t\t.resolveHqlInterpretation( hql, resultType, queryEngine.getHqlTranslator() );\n\t\tif ( SqmUtil.isSelect( hqlInterpretation.getSqmStatement() ) ) {\n\t\t\thqlInterpretation.validateResultType( resultType );\n\t\t\t// NOTE: this copy is to isolate the actual AST tree from the\n\t\t\t// one stored in the interpretation cache\n\t\t\treturn (SqmSelectStatement<T>)\n\t\t\t\t\thqlInterpretation.getSqmStatement()\n\t\t\t\t\t\t\t.copy( noParamCopyContext( SqmQuerySource.CRITERIA ) );\n\t\t}\n\t\telse {\n\t\t\tthrow new IllegalSelectQueryException( \"Expecting a selection query, but found '\" + hql + \"'\", hql );\n\t\t}\n\t}\n\n\t/**\n\t * Used during construction to resolve an incoming named query reference\n\t * and produce the corresponding SQM tree.\n\t */\n\t@Nonnull\n\tprivate static <T> SqmSelectStatement<T> resolveSqmTree(\n\t\t\t@Nonnull NamedSqmQueryMemento<?> sqmMemento,\n\t\t\t@Nonnull Class<T> resultType,\n\t\t\t@Nonnull QueryEngine queryEngine) {\n\t\tfinal var sqmStatement = sqmMemento.getSqmStatement();\n\t\tif ( sqmStatement == null ) {\n\t\t\treturn resolveSqmTree( sqmMemento.getHqlString(), resultType, queryEngine );\n\t\t}\n\t\telse if ( SqmUtil.isSelect( sqmStatement ) ) {\n\t\t\t//noinspection unchecked","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/specification/internal/SelectionSpecificationImpl.java#L328-L364","documentation":"Error \"Expecting a selection query, but found '{}'\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A Specification is given a statement of the wrong kind: Expecting a selection query, but found '<value>'","commonSituations":"Passing a select statement to MutationSpecification or a mutation statement to SelectionSpecification.","solutions":["A selection specification requires a selection query. Supply an HQL/criteria select statement."],"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"}