{"record":{"id":"a6ced14571a5abf6","repo":"hibernate/hibernate-orm","slug":"fetch-graph-has-wrong-root-type","errorCode":null,"errorMessage":"Fetch graph has wrong root type","messagePattern":"Fetch graph has wrong root type","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java","lineNumber":2248,"sourceCode":"\t\t\t\t// can't have both\n\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\"Passed properties contained both a LOAD and a FETCH graph which is illegal - \" +\n\t\t\t\t\t\t\"only one should be passed\"\n\t\t\t\t);\n\t\t\t}\n\t\t\tgraphSemantic = GraphSemantic.FETCH;\n\t\t\tgraph = fetchHint;\n\t\t}\n\t\telse if ( loadHint != null ) {\n\t\t\tgraphSemantic = GraphSemantic.LOAD;\n\t\t\tgraph = loadHint;\n\t\t}\n\t\telse {\n\t\t\tgraphSemantic = null;\n\t\t\tgraph = null;\n\t\t}\n\t\tif ( graph != null && graph.getGraphedType().getJavaType() != entityClass ) {\n\t\t\tthrow new IllegalArgumentException( \"Fetch graph has wrong root type\" );\n\t\t}\n\t\t@SuppressWarnings( \"unchecked\" ) // safe, we just checked\n\t\tfinal var castGraph = (RootGraphImplementor<T>) graph;\n\t\treturn byKey( entityClass, entityDescriptor, graphSemantic, castGraph, options );\n\t}\n\n\t@Nullable\n\tprivate static RootGraphImplementor<?> loadGraphFromHints(Map<String, Object> properties) {\n\t\tif ( properties != null ) {\n\t\t\tfinal var loadHint = (RootGraphImplementor<?>) properties.get( HINT_JAVAEE_LOAD_GRAPH );\n\t\t\tif ( loadHint == null ) {\n\t\t\t\treturn (RootGraphImplementor<?>) properties.get( HINT_SPEC_LOAD_GRAPH );\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn loadHint;\n\t\t\t}\n\t\t}\n\t\telse {","sourceCodeStart":2230,"sourceCodeEnd":2266,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java#L2230-L2266","documentation":"Error \"Fetch graph has wrong root type\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java:2248 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use an entity graph whose entity type matches the result type of the find/query call.","Create the graph with createEntityGraph(TheCorrectEntity.class) before passing it."],"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"}