HHH-18536 - Support implicit "this" alias in HQL
This commit is contained in:
parent
08bd466703
commit
e574f88fd6
|
@ -16,8 +16,8 @@ import java.util.function.Function;
|
||||||
import org.hibernate.jpa.spi.JpaCompliance;
|
import org.hibernate.jpa.spi.JpaCompliance;
|
||||||
import org.hibernate.metamodel.model.domain.BasicDomainType;
|
import org.hibernate.metamodel.model.domain.BasicDomainType;
|
||||||
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
||||||
import org.hibernate.query.criteria.JpaCrossJoin;
|
|
||||||
import org.hibernate.query.SemanticException;
|
import org.hibernate.query.SemanticException;
|
||||||
|
import org.hibernate.query.criteria.JpaCrossJoin;
|
||||||
import org.hibernate.query.hql.HqlLogging;
|
import org.hibernate.query.hql.HqlLogging;
|
||||||
import org.hibernate.query.hql.spi.SqmCreationProcessingState;
|
import org.hibernate.query.hql.spi.SqmCreationProcessingState;
|
||||||
import org.hibernate.query.hql.spi.SqmPathRegistry;
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,6 @@ import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@SessionFactory
|
@SessionFactory
|
||||||
@DomainModel(annotatedClasses = HQLThisTest.This.class)
|
@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 {
|
public class HQLThisTest {
|
||||||
@Test
|
@Test
|
||||||
void test(SessionFactoryScope scope) {
|
void test(SessionFactoryScope scope) {
|
||||||
|
|
Loading…
Reference in New Issue