HHH-17116 Small fixes to criteria copy logic for qualified joins

This commit is contained in:
Marco Belladelli 2023-08-28 14:47:44 +02:00
parent 8a89cf74e6
commit 0175edef61
No known key found for this signature in database
GPG Key ID: D1D0C3030AE3AA35
4 changed files with 14 additions and 11 deletions

View File

@ -61,8 +61,7 @@ public abstract class AbstractSqmPath<T> extends AbstractSqmExpression<T> implem
}
protected void copyTo(AbstractSqmPath<T> target, SqmCopyContext context) {
assert lhs == null || lhs.getNavigablePath() == target.getLhs().getNavigablePath()
|| getRoot( lhs ).getNodeType() instanceof SqmPolymorphicRootDescriptor;
assert navigablePathsMatch( target );
super.copyTo( target, context );
if ( reusablePaths != null ) {
target.reusablePaths = new HashMap<>( reusablePaths.size() );
@ -72,6 +71,13 @@ public abstract class AbstractSqmPath<T> extends AbstractSqmExpression<T> implem
}
}
// meant for assertions only
private boolean navigablePathsMatch(AbstractSqmPath<T> target) {
final SqmPath<?> targetLhs = target.getLhs() != null ? target.getLhs() : target.findRoot();
return lhs == null || lhs.getNavigablePath() == targetLhs.getNavigablePath()
|| getRoot( lhs ).getNodeType() instanceof SqmPolymorphicRootDescriptor;
}
private SqmPath<?> getRoot(SqmPath<?> lhs) {
return lhs.getLhs() == null ? lhs : getRoot( lhs.getLhs() );
}

View File

@ -61,14 +61,13 @@ public class SqmCrossJoin<T> extends AbstractSqmFrom<T, T> implements JpaCrossJo
if ( existing != null ) {
return existing;
}
final SqmRoot<?> rootCopy = getRoot().copy( context );
final SqmCrossJoin<T> path = context.registerCopy(
this,
new SqmCrossJoin<>(
getNavigablePathCopy( rootCopy ),
getNavigablePath(),
getReferencedPathSource(),
getExplicitAlias(),
rootCopy
getRoot().copy( context )
)
);
copyTo( path, context );

View File

@ -91,17 +91,16 @@ public class SqmDerivedJoin<T> extends AbstractSqmQualifiedJoin<T, T> implements
if ( existing != null ) {
return existing;
}
final SqmRoot<?> rootCopy = findRoot().copy( context );
final SqmDerivedJoin<T> path = context.registerCopy(
this,
new SqmDerivedJoin<>(
getNavigablePathCopy( rootCopy ),
getNavigablePath(),
subQuery,
lateral,
getReferencedPathSource(),
getExplicitAlias(),
getSqmJoinType(),
rootCopy
findRoot().copy( context )
)
);
copyTo( path, context );

View File

@ -65,15 +65,14 @@ public class SqmEntityJoin<T> extends AbstractSqmQualifiedJoin<T, T> implements
if ( existing != null ) {
return existing;
}
final SqmRoot<?> rootCopy = getRoot().copy( context );
final SqmEntityJoin<T> path = context.registerCopy(
this,
new SqmEntityJoin<>(
getNavigablePathCopy( rootCopy ),
getNavigablePath(),
getReferencedPathSource(),
getExplicitAlias(),
getSqmJoinType(),
rootCopy
getRoot().copy( context )
)
);
copyTo( path, context );