{"record":{"id":"f9659e3dde3b0f2c","repo":"hibernate/hibernate-orm","slug":"entity-graph-not-supported-for-procedurecall","errorCode":null,"errorMessage":"Entity graph not supported for ProcedureCall","messagePattern":"Entity graph 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":337,"sourceCode":"\t@Override\n\t@Nonnull\n\tpublic ProcedureCallImplementor<R> setLockMode(@Nonnull LockModeType lockMode) {\n\t\tthrow new IllegalStateException( \"Locking not supported for ProcedureCall\" );\n\t}\n\n\t@Override\n\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() {","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java#L319-L355","documentation":"setEntityGraph(graph, semantic) attaches a fetch graph so a JPQL/HQL selection eagerly fetches chosen associations. Hibernate never translates a stored-procedure call, so its fetching cannot be altered by a graph; ProcedureCallImpl therefore throws UnsupportedOperationException. The method is deprecated on this path — graphs are a SelectionQuery feature only.","triggerScenarios":"Calling setEntityGraph(graph, GraphSemantic.FETCH) on a ProcedureCall, typically from generic repository code that applies graphs to every Query to fix lazy-loading issues.","commonSituations":"N+1 remediation passes that attach graphs globally; shared query executors taking (Query, EntityGraph); upgrading code where setEntityGraph compiled fine on HQL queries but also receives procedure calls.","solutions":["Apply graphs only after an instanceof SelectionQuery check.","If procedure results under-fetch, return the associated columns from the procedure and map them explicitly via SqlResultSetMapping/constructor expressions."],"exampleFix":"// before\nquery.setEntityGraph(graph, GraphSemantic.FETCH); // query is a ProcedureCall -> throws\n\n// after\nif (query instanceof org.hibernate.query.SelectionQuery<?> sq) {\n    sq.setEntityGraph(graph, GraphSemantic.FETCH);\n}\n// procedure path: rely on the procedure's own result mapping","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean supportsEntityGraph(jakarta.persistence.Query q) {\n    return q instanceof org.hibernate.query.SelectionQuery;\n}","tryCatchPattern":"try {\n    q.setEntityGraph( graph, semantic );\n} catch (UnsupportedOperationException e) {\n    // procedure call: fetching cannot be altered; rely on the procedure's result mapping\n}","preventionTips":["Apply graphs only to SelectionQuery instances.","Fix procedure under-fetching in the procedure/result mapping, not with graphs."],"tags":["hibernate","stored-procedure","entity-graph","fetching"],"backgroundTag":"entity-graph-unsupported","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}