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
- Read the cause exception first - fix that, not this message
- Remove or narrow the failing fetch (named by parent path -> fetchable) and retry to confirm
- If the cause is a bag conflict, apply the multiple-bag fixes (OrderColumn/Set/split queries)
- 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
- Always log the cause chain - this exception is only a wrapper
- Keep entity graphs shallow and test every graph against a real SessionFactory
- Introduce fetches incrementally so the breaking fetch is identifiable in bisect history
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
- Insert conflict 'do update' clause with constraint name is n
- Summarization is not supported by DBMS
- Insert conflict 'do update' clause with constraint name is n
- Locking with set operators is not supported
- Insert conflict 'do update' clause with constraint name is n
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/b58a0206d57b2ae3.
Report an issue: GitHub.