Skip to content

Commit

Permalink
HHH-16483 Delay copying of cte statement definitions to handle recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
mbladel committed May 3, 2023
1 parent 5578109 commit c08af74
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
public class SqmCteStatement<T> extends AbstractSqmNode implements SqmVisitableNode, JpaCteCriteria<T> {
private final SqmCteContainer cteContainer;
private final SqmCteTable<T> cteTable;
private final SqmSelectQuery<?> cteDefinition;
private SqmSelectQuery<?> cteDefinition;
private CteMaterialization materialization;
private CteSearchClauseKind searchClauseKind;
private List<JpaSearchOrder> searchBySpecifications;
Expand Down Expand Up @@ -146,13 +146,13 @@ public SqmCteStatement<T> copy(SqmCopyContext context) {
if ( existing != null ) {
return existing;
}
return context.registerCopy(
final SqmCteStatement<T> copy = context.registerCopy(
this,
new SqmCteStatement<>(
nodeBuilder(),
cteContainer,
cteTable,
cteDefinition.copy( context ),
null,
materialization,
searchClauseKind,
searchBySpecifications,
Expand All @@ -164,6 +164,10 @@ public SqmCteStatement<T> copy(SqmCopyContext 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
Expand Down

0 comments on commit c08af74

Please sign in to comment.