{"record":{"id":"9b919db3d907a392","repo":"hibernate/hibernate-orm","slug":"procedurecall-cannot-be-treated-as-mutationquery","errorCode":null,"errorMessage":"ProcedureCall cannot be treated as MutationQuery","messagePattern":"ProcedureCall cannot be treated as MutationQuery","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java","lineNumber":282,"sourceCode":"\t\tthrow new IllegalArgumentException( \"ProcedureCall cannot be treated as SelectionQuery\" );\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic <X> SelectionQueryImplementor<X> asSelectionQuery(EntityGraph<X> entityGraph) {\n\t\tthrow new IllegalArgumentException( \"ProcedureCall cannot be treated as SelectionQuery\" );\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic <X> SelectionQueryImplementor<X> withResultSetMapping(@Nonnull jakarta.persistence.sql.ResultSetMapping<X> mapping) {\n\t\tthrow new IllegalArgumentException( \"ProcedureCall cannot be treated as SelectionQuery\" );\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic MutationQueryImplementor<R> asMutationQuery() {\n\t\tthrow new IllegalArgumentException( \"ProcedureCall cannot be treated as MutationQuery\" );\n\t}\n\n\t// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\t// Options\n\t@Override\n\t@Nonnull\n\tpublic ProcedureCallImplementor<R> setComment(@Nullable String comment) {\n\t\tcheckNotClosed();\n\t\tsuper.setComment( comment );\n\t\treturn this;\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic ProcedureCallImplementor<R> setQueryFlushMode(@Nonnull QueryFlushMode queryFlushMode) {\n\t\tcheckNotClosed();\n\t\tsuper.setQueryFlushMode( queryFlushMode );\n\t\treturn this;","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java#L264-L300","documentation":"The mutation counterpart of the same refusal: asMutationQuery() exists on the common query contract, but ProcedureCallImpl throws IllegalArgumentException because a stored-procedure call is executed via ProcedureCall.execute()/executeUpdate(), not converted into the SQM MutationQuery pipeline used for HQL/ Criteria DML.","triggerScenarios":"Calling asMutationQuery() on a ProcedureCall (session.createStoredProcedureQuery(...).asMutationQuery()); shared helpers that convert every query to MutationQuery before calling executeUpdate().","commonSituations":"Generic write-path code that accepts Query and normalizes via asMutationQuery(); 6.5+ migrations of (MutationQuery) casts; DML wrappers intended to also cover procedures.","solutions":["Call executeUpdate() directly on the ProcedureCall — it is supported there without conversion.","Add an instanceof ProcedureCall branch to helpers that otherwise use asMutationQuery().","Keep procedure-based writes on the StoredProcedureQuery API, separate from HQL/Criteria mutation flows."],"exampleFix":"// before\nquery.asMutationQuery().executeUpdate(); // query is a ProcedureCall -> throws\n\n// after\nif (query instanceof ProcedureCall<?> proc) {\n    proc.executeUpdate();\n} else {\n    query.asMutationQuery().executeUpdate();\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean isProcedureCall(jakarta.persistence.Query q) {\n    return q instanceof org.hibernate.procedure.ProcedureCall;\n}","tryCatchPattern":"try {\n    query.asMutationQuery().executeUpdate();\n} catch (IllegalArgumentException e) {\n    ((ProcedureCall<?>) query).executeUpdate(); // procedures execute directly\n}","preventionTips":["Call executeUpdate() directly on ProcedureCall; no conversion exists.","Add instanceof branches in shared write paths that normalize via asMutationQuery()."],"tags":["hibernate","stored-procedure","mutation-query","query-cast"],"backgroundTag":"query-type-mismatch","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}