hibernate/hibernate-orm · error · IllegalStateException
Cannot fetch the same association twice with a different ali
Error message
Cannot fetch the same association twice with a different alias
What it means
Error "Cannot fetch the same association twice with a different alias" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/QualifiedJoinPathConsumer.java:214
SqmCreationState creationState) {
final var subPathSource = lhs.getResolvedModel().getSubPathSource( name, true );
if ( allowReuse ) {
if ( !isTerminal ) {
for ( var sqmJoin : lhs.getSqmJoins() ) {
// In order for an HQL join to be reusable, it must have the same path source,
if ( sqmJoin.getModel() == subPathSource
// and must not have a join condition.
&& sqmJoin.getJoinPredicate() == null ) {
// We explicitly allow reusing implicit joins of any type
return sqmJoin;
}
}
}
else if ( fetch ) {
final var compatibleFetchJoin = findCompatibleFetchJoin( lhs, subPathSource, joinType );
if ( compatibleFetchJoin != null ) {
if ( alias != null ) {
throw new IllegalStateException( "Cannot fetch the same association twice with a different alias" );
}
return compatibleFetchJoin;
}
}
}
if ( !(subPathSource instanceof SqmJoinable) ) {
throw new SemanticException( "Joining on basic value elements is not supported",
((SemanticQueryBuilder<?>) creationState).getQuery() );
}
@SuppressWarnings("unchecked")
final var joinSource = (SqmJoinable<U, ?>) subPathSource;
return createJoin( lhs, joinType, alias, fetch, isTerminal, allowReuse, creationState, joinSource );
}
private static <U,V> SqmFrom<?, ?> createJoin(
SqmFrom<?,U> lhs,
SqmJoinType joinType,
String alias,View on GitHub (pinned to fad1729dce)
Solutions
- Fetch the association once and reuse the alias.
- Remove the duplicate fetch join or give it the same alias.
When it happens
Trigger: A runtime precondition of the Hibernate API is violated.
Common situations: Occurs when application code or configuration does not satisfy the documented contract of the API being called.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/6b6904a314770290.
Report an issue: GitHub.