HHH-17777 Enforce no alias on fetch joins when jpa compliance is enabled

This commit is contained in:
Marco Belladelli 2024-03-07 15:23:46 +01:00 committed by Christian Beikov
parent 3ce10df785
commit 67f573a6bf
1 changed files with 16 additions and 0 deletions

View File

@ -9,6 +9,7 @@ package org.hibernate.query.sqm.tree.domain;
import org.hibernate.metamodel.model.domain.PersistentAttribute;
import org.hibernate.query.criteria.JpaExpression;
import org.hibernate.query.criteria.JpaPredicate;
import org.hibernate.query.criteria.JpaSelection;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.SemanticQueryWalker;
import org.hibernate.query.sqm.SqmJoinable;
@ -71,6 +72,7 @@ public abstract class AbstractSqmAttributeJoin<O,T>
nodeBuilder
);
this.fetched = fetched;
validateFetchAlias( alias );
}
@Override
@ -89,11 +91,25 @@ public abstract class AbstractSqmAttributeJoin<O,T>
return fetched;
}
@Override
public JpaSelection<T> alias(String name) {
validateFetchAlias( name );
return super.alias( name );
}
@Override
public void clearFetched() {
fetched = false;
}
private void validateFetchAlias(String alias) {
if ( fetched && alias != null && nodeBuilder().isJpaQueryComplianceEnabled() ) {
throw new IllegalStateException(
"The JPA specification does not permit specifying an alias for fetch joins."
);
}
}
@Override
public <X> X accept(SemanticQueryWalker<X> walker) {
return walker.visitQualifiedAttributeJoin( this );