hibernate/hibernate-orm · error · IllegalArgumentException

Graph semantic specified, but no RootGraph was supplied

Error message

Graph semantic specified, but no RootGraph was supplied

What it means

LoadQueryInfluencers.applyEntityGraph(rootGraph, graphSemantic) requires the two arguments to be non-null together: naming a GraphSemantic (FETCH or LOAD) means a graph must be supplied to interpret, so a null RootGraph with a non-null semantic is rejected with IllegalArgumentException.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/engine/spi/LoadQueryInfluencers.java:115

		temporalIdentifier = options.getTemporalIdentifier();
		for ( var filterDefinition : sessionFactory.getAutoEnabledFilters() ) {
			final var filter = new FilterImpl( filterDefinition );
			if ( enabledFilters == null ) {
				enabledFilters = new TreeMap<>();
			}
			enabledFilters.put( filterDefinition.getFilterName(), filter );
		}
		for ( var enabledFilterOption : options.getEnabledFilterOptions() ) {
			enableFilter( enabledFilterOption );
		}
	}

	@Nonnull
	public EffectiveEntityGraph applyEntityGraph(RootGraphImplementor<?> rootGraph, GraphSemantic graphSemantic) {
		final var effectiveEntityGraph = getEffectiveEntityGraph();
		if ( graphSemantic != null ) {
			if ( rootGraph == null ) {
				throw new IllegalArgumentException( "Graph semantic specified, but no RootGraph was supplied" );
			}
			effectiveEntityGraph.applyGraph( rootGraph, graphSemantic );
		}
		return effectiveEntityGraph;
	}

	@Nonnull
	public SessionFactoryImplementor getSessionFactory() {
		return sessionFactory;
	}

	@Nullable
	public Object getTemporalIdentifier() {
		return temporalIdentifier;
	}

	public void setTemporalIdentifier(@Nullable Object temporalIdentifier) {
		this.temporalIdentifier = temporalIdentifier;

View on GitHub (pinned to fad1729dce)

Solutions

  1. Pass a real RootGraph obtained from session.createEntityGraph(Class) / em.createEntityGraph(Class) or em.getEntityGraph(name)
  2. If the graph is genuinely optional, pass a null semantic as well — applyEntityGraph then leaves the effective graph untouched
  3. Null-check the graph before calling and fail fast with a descriptive message identifying the missing graph

Example fix

// before
RootGraphImplementor<?> graph = graphs.get("orderGraph"); // null if not registered
influencers.applyEntityGraph(graph, GraphSemantic.FETCH); // IllegalArgumentException

// after
RootGraphImplementor<?> graph = graphs.get("orderGraph");
if (graph == null) throw new IllegalStateException("Entity graph 'orderGraph' is not registered");
influencers.applyEntityGraph(graph, GraphSemantic.FETCH);
Defensive patterns

Strategy: validation

Validate before calling

if (semantic != null && rootGraph == null) {
    throw new IllegalArgumentException("A RootGraph is required when a GraphSemantic (" + semantic + ") is specified");
}
influencers.applyEntityGraph(rootGraph, semantic);

Prevention

When it happens

Trigger: Calling loadQueryInfluencers.applyEntityGraph(null, GraphSemantic.FETCH/LOAD) directly, or through the by-key/find-by-id load-access and find operations that pass a looked-up graph: a graph registry lookup (e.g. getEntityGraph(name)) returned null because the graph was never registered, and it was passed alongside a non-null semantic.

Common situations: Graphs looked up by name from a map or configuration that silently returned null; refactoring that made the graph argument optional; test code passing null placeholders; copy-paste from applyConfiguredGraph() flows where a null graph is only warned about.

Related errors


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