Fix processing state issues with insert-select statements

This commit is contained in:
Christian Beikov 2021-03-08 11:43:20 +01:00
parent ee52989647
commit b225beb3cc
1 changed files with 11 additions and 8 deletions

View File

@ -816,6 +816,8 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
getCurrentClauseStack()::getCurrent
)
);
currentClauseStack.push( Clause.INSERT );
final InsertStatement insertStatement;
try {
final NavigablePath rootPath = sqmStatement.getTarget().getNavigablePath();
@ -836,7 +838,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
getFromClauseAccess().registerTableGroup( rootPath, rootTableGroup );
final InsertStatement insertStatement = new InsertStatement(
insertStatement = new InsertStatement(
sqmStatement.isWithRecursive(),
cteStatements,
rootTableGroup.getPrimaryTableReference(),
@ -844,20 +846,21 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
);
List<SqmPath> targetPaths = sqmStatement.getInsertionTargetPaths();
for ( SqmPath target : targetPaths ) {
for ( SqmPath<?> target : targetPaths ) {
Assignable assignable = (Assignable) target.accept( this );
insertStatement.addTargetColumnReferences( assignable.getColumnReferences() );
}
insertStatement.setSourceSelectStatement(
visitQueryPart( selectQueryPart )
);
return insertStatement;
}
finally {
popProcessingStateStack();
currentClauseStack.pop();
}
insertStatement.setSourceSelectStatement(
visitQueryPart( selectQueryPart )
);
return insertStatement;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~