{"record":{"id":"cc1c75be92c63dcf","repo":"hibernate/hibernate-orm","slug":"a-native-sql-query-cannot-use-entitygraphs","errorCode":null,"errorMessage":"A native SQL query cannot use EntityGraphs","messagePattern":"A native SQL query cannot use EntityGraphs","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java","lineNumber":611,"sourceCode":"\t@Nonnull\n\tpublic NativeQueryImplementor<R> asSelectionQuery() {\n\t\terrorIfNotSelectForSure();\n\t\treturn this;\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic <X> NativeQueryImplementor<X> asSelectionQuery(Class<X> type) {\n\t\terrorIfNotSelectForSure();\n\t\tcheckResultType( type, resultSetMapping() );\n\t\t//noinspection unchecked\n\t\treturn (NativeQueryImplementor<X>) this;\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic <X> NativeQueryImplementor<X> asSelectionQuery(EntityGraph<X> entityGraph) {\n\t\tthrow new HibernateException( \"A native SQL query cannot use EntityGraphs\" );\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic NativeQueryImplementor<R> asMutationQuery() {\n\t\terrorIfNotSelectForSure();\n\t\treturn this;\n\t}\n\n\tprivate ParameterInterpretation resolveParameterInterpretation(\n\t\t\tString sqlString, SharedSessionContractImplementor session) {\n\t\treturn getInterpretationCache( session )\n\t\t\t\t.resolveNativeQueryParameters( sqlString,\n\t\t\t\t\t\ts -> parameterInterpretation( sqlString ) );\n\t}\n\n\tprivate ParameterInterpretationImpl parameterInterpretation(String sqlString) {\n\t\treturn ParameterInterpretationImpl.interpretParameters( sqlString, getSessionFactory() );","sourceCodeStart":593,"sourceCodeEnd":629,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java#L593-L629","documentation":"Error \"A native SQL query cannot use EntityGraphs\" thrown in hibernate/hibernate-orm.","triggerScenarios":"An API operation is invoked on a query object that does not support it.","commonSituations":"Calling query hint, locking, pagination, conversion, or mutation APIs on a query kind (native vs HQL, select vs mutation) that does not implement them.","solutions":["EntityGraphs (fetchgraph/loadgraph hints) are not supported on native SQL queries.","Remove the EntityGraph hint, or rewrite the query in HQL where EntityGraphs are supported."],"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"}