HHH-16483 Delay copying of cte statement definitions to handle recursion
This commit is contained in:
parent
444df0cdfe
commit
45ec259efe
|
@ -42,7 +42,7 @@ import jakarta.persistence.criteria.Subquery;
|
||||||
public class SqmCteStatement<T> extends AbstractSqmNode implements SqmVisitableNode, JpaCteCriteria<T> {
|
public class SqmCteStatement<T> extends AbstractSqmNode implements SqmVisitableNode, JpaCteCriteria<T> {
|
||||||
private final SqmCteContainer cteContainer;
|
private final SqmCteContainer cteContainer;
|
||||||
private final SqmCteTable<T> cteTable;
|
private final SqmCteTable<T> cteTable;
|
||||||
private final SqmSelectQuery<?> cteDefinition;
|
private SqmSelectQuery<?> cteDefinition;
|
||||||
private CteMaterialization materialization;
|
private CteMaterialization materialization;
|
||||||
private CteSearchClauseKind searchClauseKind;
|
private CteSearchClauseKind searchClauseKind;
|
||||||
private List<JpaSearchOrder> searchBySpecifications;
|
private List<JpaSearchOrder> searchBySpecifications;
|
||||||
|
@ -146,13 +146,13 @@ public class SqmCteStatement<T> extends AbstractSqmNode implements SqmVisitableN
|
||||||
if ( existing != null ) {
|
if ( existing != null ) {
|
||||||
return existing;
|
return existing;
|
||||||
}
|
}
|
||||||
return context.registerCopy(
|
final SqmCteStatement<T> copy = context.registerCopy(
|
||||||
this,
|
this,
|
||||||
new SqmCteStatement<>(
|
new SqmCteStatement<>(
|
||||||
nodeBuilder(),
|
nodeBuilder(),
|
||||||
cteContainer,
|
cteContainer,
|
||||||
cteTable,
|
cteTable,
|
||||||
cteDefinition.copy( context ),
|
null,
|
||||||
materialization,
|
materialization,
|
||||||
searchClauseKind,
|
searchClauseKind,
|
||||||
searchBySpecifications,
|
searchBySpecifications,
|
||||||
|
@ -164,6 +164,10 @@ public class SqmCteStatement<T> extends AbstractSqmNode implements SqmVisitableN
|
||||||
noCycleValue == null ? null : noCycleValue.copy( context )
|
noCycleValue == null ? null : noCycleValue.copy( context )
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
// We have to copy the definition object after registering the copy of this because for recursive CTEs
|
||||||
|
// the select query from clause may contain the current cte statement itself
|
||||||
|
copy.cteDefinition = cteDefinition.copy( context );
|
||||||
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue