{"record":{"id":"318b4320d193816f","repo":"hibernate/hibernate-orm","slug":"result-type-given-for-a-non-select-query","errorCode":null,"errorMessage":"Result type given for a non-SELECT Query","messagePattern":"Result type given for a non-SELECT Query","errorType":"exception","errorClass":"IllegalQueryOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/internal/SelectionQueryImpl.java","lineNumber":1198,"sourceCode":"\t\t\t);\n\t\t}\n\t}\n\n\n\t// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\t// Utilities\n\n\tprivate static <R> void validateQuery(Class<R> expectedResultType, SqmStatement<R> sqm, String hql) {\n\t\tif ( sqm instanceof SqmSelectStatement<R> selectStatement ) {\n\t\t\tfinal var queryPart = selectStatement.getQueryPart();\n\t\t\t// For criteria queries, we have to validate the fetch structure here\n\t\t\tqueryPart.validateQueryStructureAndFetchOwners();\n\t\t\tvalidateCriteriaQuery( queryPart );\n\t\t\tselectStatement.validateResultType( expectedResultType );\n\t\t}\n\t\telse if ( sqm instanceof AbstractSqmDmlStatement<R> update ) {\n\t\t\tif ( expectedResultType != null ) {\n\t\t\t\tthrow new IllegalQueryOperationException( \"Result type given for a non-SELECT Query\", hql, null );\n\t\t\t}\n\t\t\tupdate.validate( hql );\n\t\t}\n\t}\n\n\tprivate SelectQueryPlan<R> resolveQueryPlan() {\n\t\tfinal var queryCache = getInterpretationCache();\n\t\tif ( queryCache.isEnabled() ) {\n\t\t\tfinal var cacheKey = createInterpretationsKey( this );\n\t\t\treturn cacheKey == null\n\t\t\t\t\t? buildSelectQueryPlan()\n\t\t\t\t\t: queryCache.resolveSelectQueryPlan( cacheKey, this::buildSelectQueryPlan );\n\t\t}\n\t\telse {\n\t\t\treturn buildSelectQueryPlan();\n\t\t}\n\n\t}","sourceCodeStart":1180,"sourceCodeEnd":1216,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/internal/SelectionQueryImpl.java#L1180-L1216","documentation":"Error \"Result type given for a non-SELECT Query\" thrown in hibernate/hibernate-orm.","triggerScenarios":"The requested result type does not match what the query produces: Result type given for a non-SELECT Query","commonSituations":"Creating a typed query whose result class differs from the query root/select item type, or passing a result type for a non-select statement.","solutions":["A result type was specified for a non-SELECT query. Remove the result type, or use a select query."],"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"}