hibernate/hibernate-orm · error · HibernateException

Could not generate fetch : %s -> %s

Error message

Could not generate fetch : %s -> %s

What it means

A pass-through wrapper: the underlying fetch construction (fetchParent.generateFetchableFetch) threw a RuntimeException, and Hibernate rethrows it as a HibernateException naming the fetch parent path and fetchable name with the original exception as cause. The real failure is always in the cause - this message only tells you which fetch broke.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/sql/spi/BaseSqmToSqlAstConverter.java:9187

			String alias) {
		// fetch has access to its parent in addition to the parent having its fetches.
		//
		// we could sever the parent -> fetch link ... it would not be "seen" while walking
		// but it would still have access to its parent info - and be able to access its
		// "initializing" state as part of AfterLoadAction

		try {
			return fetchParent.generateFetchableFetch(
					fetchable,
					fetchablePath,
					fetchTiming,
					joined,
					alias,
					this
			);
		}
		catch (RuntimeException e) {
			throw new HibernateException(
					String.format(
							Locale.ROOT,
							"Could not generate fetch : %s -> %s",
							fetchParent.getNavigablePath(),
							fetchable.getFetchableName()
					),
					e
			);
		}
	}
//
//	private void applyOrdering(TableGroup tableGroup, PluralAttributeMapping pluralAttributeMapping) {
//		if ( pluralAttributeMapping.getOrderByFragment() != null ) {
//			applyOrdering( tableGroup, pluralAttributeMapping.getOrderByFragment() );
//		}
//
//		if ( pluralAttributeMapping.getManyToManyOrderByFragment() != null ) {
//			applyOrdering( tableGroup, pluralAttributeMapping.getManyToManyOrderByFragment() );

View on GitHub (pinned to fad1729dce)

Solutions

  1. Read the cause exception first - fix that, not this message
  2. Remove or narrow the failing fetch (named by parent path -> fetchable) and retry to confirm
  3. If the cause is a bag conflict, apply the multiple-bag fixes (OrderColumn/Set/split queries)
  4. Reduce fetch depth or fetch the problem collection lazily with batch fetching
Defensive patterns

Strategy: try-catch

Try / catch

try {
    return query.getResultList();
} catch (org.hibernate.HibernateException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Could not generate fetch")) {
    	log.error("Fetch {} failed; cause: {}", e.getMessage(), e.getCause(), e);
    	return runWithoutFetch(fetchName); // retry with the offending fetch removed (e.g. LAZY hint)
    }
    throw e;
}

Prevention

When it happens

Trigger: Any fetch whose construction fails: multiple-bag conflicts inside a fetched association, dialects lacking a type needed by a fetched column, circular fetch paths, subclass-table mappings with missing selectable mappings, or any of the other translation errors occurring inside fetch processing.

Common situations: Deep or wide entity graphs; enabling join fetch on a mapping that worked lazily; upgrading Hibernate where a mapped type became stricter; dialect-specific column types inside fetched embeddables.

Related errors


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