HHH-17606 Fix nested generic join path resolution
This commit is contained in:
parent
fa0f5d414b
commit
cfe41ed8bb
|
@ -187,7 +187,10 @@ public class QualifiedJoinPathConsumer implements DotIdentifierConsumer {
|
||||||
boolean isTerminal,
|
boolean isTerminal,
|
||||||
boolean allowReuse,
|
boolean allowReuse,
|
||||||
SqmCreationState creationState) {
|
SqmCreationState creationState) {
|
||||||
final SqmPathSource<?> subPathSource = subPathSource( lhs, name, creationState );
|
final SqmPathSource<?> subPathSource = lhs.getResolvedModel().getSubPathSource(
|
||||||
|
name,
|
||||||
|
creationState.getCreationContext().getJpaMetamodel()
|
||||||
|
);
|
||||||
if ( allowReuse && !isTerminal ) {
|
if ( allowReuse && !isTerminal ) {
|
||||||
for ( SqmJoin<?, ?> sqmJoin : lhs.getSqmJoins() ) {
|
for ( SqmJoin<?, ?> sqmJoin : lhs.getSqmJoins() ) {
|
||||||
if ( sqmJoin.getAlias() == null && sqmJoin.getReferencedPathSource() == subPathSource ) {
|
if ( sqmJoin.getAlias() == null && sqmJoin.getReferencedPathSource() == subPathSource ) {
|
||||||
|
@ -200,18 +203,6 @@ public class QualifiedJoinPathConsumer implements DotIdentifierConsumer {
|
||||||
return createJoin( lhs, joinType, alias, fetch, isTerminal, allowReuse, creationState, joinSource );
|
return createJoin( lhs, joinType, alias, fetch, isTerminal, allowReuse, creationState, joinSource );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <U> SqmPathSource<?> subPathSource(SqmFrom<?, U> lhs, String name, SqmCreationState creationState) {
|
|
||||||
final SqmPathSource<U> referencedPathSource = lhs.getReferencedPathSource();
|
|
||||||
// We need to use referencedPathSource when it is not generic since the getResolvedModel() method would
|
|
||||||
// return the association attribute as a path source and for treated paths that might correspond to a
|
|
||||||
// different entity type (usually the first in alphabetical order) and not the correct treat target
|
|
||||||
final SqmPathSource<?> pathSource =
|
|
||||||
referencedPathSource.isGeneric()
|
|
||||||
? lhs.getResolvedModel()
|
|
||||||
: referencedPathSource;
|
|
||||||
return pathSource.getSubPathSource( name, creationState.getCreationContext().getJpaMetamodel() );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <U,V> SqmFrom<?, ?> createJoin(
|
private static <U,V> SqmFrom<?, ?> createJoin(
|
||||||
SqmFrom<?,U> lhs,
|
SqmFrom<?,U> lhs,
|
||||||
SqmJoinType joinType,
|
SqmJoinType joinType,
|
||||||
|
|
|
@ -162,8 +162,7 @@ public abstract class AbstractSqmPath<T> extends AbstractSqmExpression<T> implem
|
||||||
public SqmPathSource<?> getResolvedModel() {
|
public SqmPathSource<?> getResolvedModel() {
|
||||||
final DomainType<?> lhsType;
|
final DomainType<?> lhsType;
|
||||||
final SqmPathSource<T> pathSource = getReferencedPathSource();
|
final SqmPathSource<T> pathSource = getReferencedPathSource();
|
||||||
if ( pathSource.isGeneric() && ( lhsType = getLhs().getReferencedPathSource()
|
if ( pathSource.isGeneric() && ( lhsType = getLhs().getResolvedModel().getSqmPathType() ) instanceof ManagedDomainType ) {
|
||||||
.getSqmPathType() ) instanceof ManagedDomainType ) {
|
|
||||||
final PersistentAttribute<?, ?> concreteAttribute = ( (ManagedDomainType<?>) lhsType ).findConcreteGenericAttribute(
|
final PersistentAttribute<?, ?> concreteAttribute = ( (ManagedDomainType<?>) lhsType ).findConcreteGenericAttribute(
|
||||||
pathSource.getPathName()
|
pathSource.getPathName()
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue