hibernate/hibernate-orm · error · SemanticException
Query specified join fetching, but the owner of the fetched
Error message
Query specified join fetching, but the owner of the fetched association was not present in the select list [%s]
What it means
Error "Query specified join fetching, but the owner of the fetched association was not present in the select list [%s]" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/select/SqmQuerySpec.java:631
}
}
for ( var sqmTreat : sqmJoin.getSqmTreats() ) {
if ( sqmTreat instanceof SqmAttributeJoin<?, ?> attributeJoin ) {
if ( attributeJoin.isFetched() ) {
assertFetchOwner( selectedFromSet, attributeJoin.getLhs(), attributeJoin );
// Only need to check the first level
continue;
}
}
validateFetchOwners( selectedFromSet, sqmTreat );
}
validateFetchOwners( selectedFromSet, sqmJoin );
}
}
private void assertFetchOwner(Set<SqmFrom<?, ?>> selectedFromSet, SqmFrom<?, ?> owner, SqmJoin<?, ?> fetchJoin) {
if ( !selectedFromSet.contains( owner ) ) {
throw new SemanticException(
"Query specified join fetching, but the owner " +
"of the fetched association was not present in the select list " +
"[" + fetchJoin.asLoggableText() + "]"
);
}
}
@Override
public void appendHqlString(StringBuilder hql, SqmRenderContext context) {
final var selections = selectClause.getSelections();
if ( !selections.isEmpty() ) {
hql.append( "select " );
if ( selectClause.isDistinct() ) {
hql.append( "distinct " );
}
selections.get( 0 ).appendHqlString( hql, context );
for ( int i = 1; i < selections.size(); i++ ) {
hql.append( ", " );View on GitHub (pinned to fad1729dce)
Solutions
- Include the owner of the fetched association in the select list (select the root/entity that owns the join fetch).
- Remove the join fetch if the owning entity is not selected, and load the association lazily or via a separate query.
- Use an entity graph or a dedicated fetch query instead of join fetching an association whose owner is not returned.
When it happens
Trigger: A join fetch is declared but the owner of the fetched association is not among the selected roots.
Common situations: Fetching an association of a root that is not returned (JPA restriction); select the owner or drop the fetch.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/d83ea26d110defab.
Report an issue: GitHub.