HHH-18536 - Support implicit "this" alias in HQL

This commit is contained in:
Steve Ebersole 2024-08-28 17:24:53 -05:00
parent 08bd466703
commit e574f88fd6
2 changed files with 10 additions and 3 deletions

View File

@ -16,8 +16,8 @@ import java.util.function.Function;
import org.hibernate.jpa.spi.JpaCompliance;
import org.hibernate.metamodel.model.domain.BasicDomainType;
import org.hibernate.metamodel.model.domain.JpaMetamodel;
import org.hibernate.query.criteria.JpaCrossJoin;
import org.hibernate.query.SemanticException;
import org.hibernate.query.criteria.JpaCrossJoin;
import org.hibernate.query.hql.HqlLogging;
import org.hibernate.query.hql.spi.SqmCreationProcessingState;
import org.hibernate.query.hql.spi.SqmPathRegistry;
@ -254,6 +254,15 @@ public class SqmPathRegistryImpl implements SqmPathRegistry {
}
}
final boolean onlyOneFrom = sqmFromByPath.size() == 1;
if ( onlyOneFrom && localAlias.equals( "this" ) ) {
final SqmRoot<?> root = (SqmRoot<?>) sqmFromByPath.entrySet().iterator().next().getValue();
if ( root.getAlias() == null ) {
//noinspection unchecked
return (X) root;
}
}
return null;
}

View File

@ -13,8 +13,6 @@ import org.junit.jupiter.api.Test;
@SessionFactory
@DomainModel(annotatedClasses = HQLThisTest.This.class)
@FailureExpected( jiraKey = "HHH-18536", reason = "Support implicit \"this\" alias in HQL" )
@Jira( "https://hibernate.atlassian.net/browse/HHH-18536" )
public class HQLThisTest {
@Test
void test(SessionFactoryScope scope) {