hibernate/hibernate-orm · error · AnnotationException

Attribute '${attribute}' is annotated '@Fetch' for graph '${

Error message

Attribute '${attribute}' is annotated '@Fetch' for graph '${graph}' with an unknown subgraph '${subgraph}'

What it means

Error "Attribute '${attribute}' is annotated '@Fetch' for graph '${graph}' with an unknown subgraph '${subgraph}'" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/NamedGraphCreatorJpa.java:156

			String subgraphName,
			AttributeNodeImplementor<T,E,K> attributeNode,
			boolean isKeySubGraph,
			List<FetchGraphContribution> fetchContributions) {
		for ( var namedSubgraph : namedEntityGraph.subgraphs() ) {
			if ( subgraphName.equals( namedSubgraph.name() ) ) {
				applyNamedAttributeNodes( namedSubgraph.attributeNodes(), namedEntityGraph,
						createSubgraph( attributeNode, isKeySubGraph, namedSubgraph.type() ), subgraphName, fetchContributions );
			}
		}
	}

	private void validateFetchContributions() {
		validateConflictingFetchContributions();
		for ( var fetchContribution : fetchContributions ) {
			if ( fetchContribution.appliesTo( name ) ) {
				for ( var subgraphName : fetchContribution.subgraphNames() ) {
					if ( !isNamedSubgraph( subgraphName ) && modelsContext == null ) {
						throw new AnnotationException(
								"Attribute '" + fetchContribution.attributeName()
										+ "' is annotated '@Fetch' for graph '" + name
										+ "' with an unknown subgraph '" + subgraphName + "'" );
					}
				}
			}
		}
	}

	private void validateConflictingFetchContributions() {
		for ( int i = 0; i < fetchContributions.size(); i++ ) {
			final var first = fetchContributions.get( i );
			if ( !first.appliesTo( name ) ) {
				continue;
			}
			for ( int j = i + 1; j < fetchContributions.size(); j++ ) {
				final var second = fetchContributions.get( j );
				if ( sameFetchTarget( first, second ) ) {

View on GitHub (pinned to fad1729dce)

Solutions

  1. Correct the subgraph name in @Fetch to a subgraph defined in the named entity graph.

When it happens

Trigger: A named entity graph / fetch declaration references unknown or incompatible types, attributes, or subgraphs.

Common situations: @Fetch pointing at an unknown graph, subgraph types that are not subtypes of the attribute type, or conflicting fetch options for the same attribute.


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