hibernate/hibernate-orm · error · IllegalArgumentException

Fetch graph has wrong root type

Error message

Fetch graph has wrong root type

What it means

Error "Fetch graph has wrong root type" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java:2248

				// can't have both
				throw new IllegalArgumentException(
						"Passed properties contained both a LOAD and a FETCH graph which is illegal - " +
						"only one should be passed"
				);
			}
			graphSemantic = GraphSemantic.FETCH;
			graph = fetchHint;
		}
		else if ( loadHint != null ) {
			graphSemantic = GraphSemantic.LOAD;
			graph = loadHint;
		}
		else {
			graphSemantic = null;
			graph = null;
		}
		if ( graph != null && graph.getGraphedType().getJavaType() != entityClass ) {
			throw new IllegalArgumentException( "Fetch graph has wrong root type" );
		}
		@SuppressWarnings( "unchecked" ) // safe, we just checked
		final var castGraph = (RootGraphImplementor<T>) graph;
		return byKey( entityClass, entityDescriptor, graphSemantic, castGraph, options );
	}

	@Nullable
	private static RootGraphImplementor<?> loadGraphFromHints(Map<String, Object> properties) {
		if ( properties != null ) {
			final var loadHint = (RootGraphImplementor<?>) properties.get( HINT_JAVAEE_LOAD_GRAPH );
			if ( loadHint == null ) {
				return (RootGraphImplementor<?>) properties.get( HINT_SPEC_LOAD_GRAPH );
			}
			else {
				return loadHint;
			}
		}
		else {

View on GitHub (pinned to fad1729dce)

Solutions

  1. Use an entity graph whose entity type matches the result type of the find/query call.
  2. Create the graph with createEntityGraph(TheCorrectEntity.class) before passing it.

When it happens

Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java:2248 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/a6ced14571a5abf6. Report an issue: GitHub.