{"record":{"id":"a8a915f5fe2424c8","repo":"hibernate/hibernate-orm","slug":"fetch-profiles-not-supported-for-procedurecall","errorCode":null,"errorMessage":"Fetch profiles not supported for ProcedureCall","messagePattern":"Fetch profiles not supported for ProcedureCall","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java","lineNumber":344,"sourceCode":"\t@Nonnull\n\tpublic ProcedureCallImplementor<R> addQueryHint(@Nonnull String hint) {\n\t\tcheckNotClosed();\n\t\tsuper.addQueryHint( hint );\n\t\treturn this;\n\t}\n\n\t@Override @Deprecated\n\t@SuppressWarnings(\"removal\")\n\t@Nonnull\n\tpublic Query<R> setEntityGraph(@Nonnull EntityGraph<? super R> graph, @Nonnull GraphSemantic semantic) {\n\t\tthrow new UnsupportedOperationException( \"Entity graph not supported for ProcedureCall\" );\n\t}\n\n\t@Override @Deprecated\n\t@SuppressWarnings(\"removal\")\n\t@Nonnull\n\tpublic Query<R> enableFetchProfile(@Nonnull String profileName) {\n\t\tthrow new UnsupportedOperationException( \"Fetch profiles not supported for ProcedureCall\" );\n\t}\n\n\t@Override @Deprecated\n\t@SuppressWarnings(\"removal\")\n\t@Nonnull\n\tpublic Query<R> disableFetchProfile(@Nonnull String profileName) {\n\t\tthrow new UnsupportedOperationException( \"Fetch profiles not supported for ProcedureCall\" );\n\t}\n\n\t@Override\n\tpublic boolean isQueryPlanCacheable() {\n\t\treturn false;\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic ProcedureCallImplementor<R> setQueryPlanCacheable(boolean queryPlanCacheable) {\n\t\tthrow new UnsupportedOperationException( \"Not supported\" );","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java#L326-L362","documentation":"enableFetchProfile(profileName) activates a named fetch profile (declared via @FetchProfile) on a query. Fetch profiles alter association fetching during query translation, which never happens for a stored-procedure call; ProcedureCallImpl rejects the call with UnsupportedOperationException.","triggerScenarios":"Calling enableFetchProfile(\"order.with-lines\") on a ProcedureCall/StoredProcedureQuery — commonly from generic optimization code that enables a profile on every query in a service method.","commonSituations":"Codebases with global fetch-profile strategies applied to all queries; profiling/performance tooling that toggles profiles around query execution.","solutions":["Restrict enableFetchProfile to SelectionQuery instances (instanceof guard).","For procedures, have the procedure return the extra data and map it with an explicit SqlResultSetMapping."],"exampleFix":"// before\nquery.enableFetchProfile(\"order.with-lines\"); // query is a ProcedureCall -> throws\n\n// after\nif (query instanceof org.hibernate.query.SelectionQuery<?> sq) {\n    sq.enableFetchProfile(\"order.with-lines\");\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean supportsFetchProfile(jakarta.persistence.Query q) {\n    return q instanceof org.hibernate.query.SelectionQuery;\n}","tryCatchPattern":"try {\n    q.enableFetchProfile( profileName );\n} catch (UnsupportedOperationException e) {\n    // procedure call: fetch profiles only affect translated HQL/Criteria queries\n}","preventionTips":["Scope fetch-profile toggles to SelectionQuery.","Avoid global interceptors that enable profiles on every Query."],"tags":["hibernate","stored-procedure","fetch-profile","fetching"],"backgroundTag":"fetch-profile-unsupported","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}