Skip to content

Commit 7266a65

Browse files
committed
HHH-19314 StackOverflowException when using onConflict with createCriteriaInsertValues and createCriteriaInsertSelect
1 parent f85eefb commit 7266a65

File tree

4 files changed

+34
-16
lines changed

4 files changed

+34
-16
lines changed

hibernate-core/src/main/java/org/hibernate/query/sqm/tree/insert/AbstractSqmInsertStatement.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ protected List<SqmPath<?>> copyInsertionTargetPaths(SqmCopyContext context) {
7171
}
7272
}
7373

74+
void setConflictClause(SqmConflictClause<T> conflictClause) {
75+
this.conflictClause = conflictClause;
76+
}
77+
7478
protected void verifyInsertTypesMatch(
7579
List<SqmPath<?>> insertionTargetPaths,
7680
List<? extends SqmTypedNode<?>> expressions) {

hibernate-core/src/main/java/org/hibernate/query/sqm/tree/insert/SqmConflictClause.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private SqmConflictClause(
5252
this.insertStatement = insertStatement;
5353
this.excludedRoot = excludedRoot;
5454
this.constraintName = constraintName;
55-
this.constraintPaths = Collections.unmodifiableList( constraintPaths );
55+
this.constraintPaths = constraintPaths == null ? null : Collections.unmodifiableList( constraintPaths );
5656
this.updateAction = updateAction;
5757
}
5858

@@ -155,7 +155,7 @@ public SqmConflictClause<T> copy(SqmCopyContext context) {
155155
insertStatement.copy( context ),
156156
excludedRoot.copy( context ),
157157
constraintName,
158-
copyOf( constraintPaths, context ),
158+
constraintPaths == null ? null : copyOf( constraintPaths, context ),
159159
updateAction == null ? null : updateAction.copy( context )
160160
)
161161
);

hibernate-core/src/main/java/org/hibernate/query/sqm/tree/insert/SqmInsertSelectStatement.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,26 @@ public SqmInsertSelectStatement<T> copy(SqmCopyContext context) {
8181
if ( existing != null ) {
8282
return existing;
8383
}
84-
return context.registerCopy(
85-
this,
86-
new SqmInsertSelectStatement<>(
87-
nodeBuilder(),
88-
context.getQuerySource() == null ? getQuerySource() : context.getQuerySource(),
89-
copyParameters( context ),
90-
copyCteStatements( context ),
91-
getTarget().copy( context ),
92-
copyInsertionTargetPaths( context ),
93-
getConflictClause() == null ? null : getConflictClause().copy( context ),
94-
selectQueryPart.copy( context )
95-
)
84+
final SqmInsertSelectStatement<T> sqmInsertSelectStatementCopy = new SqmInsertSelectStatement<>(
85+
nodeBuilder(),
86+
context.getQuerySource() == null ? getQuerySource() : context.getQuerySource(),
87+
copyParameters( context ),
88+
copyCteStatements( context ),
89+
getTarget().copy( context ),
90+
null,
91+
null,
92+
selectQueryPart.copy( context )
9693
);
94+
95+
context.registerCopy( this, sqmInsertSelectStatementCopy );
96+
97+
sqmInsertSelectStatementCopy.setInsertionTargetPaths( copyInsertionTargetPaths( context ) );
98+
99+
if ( getConflictClause() != null ) {
100+
sqmInsertSelectStatementCopy.setConflictClause( getConflictClause().copy( context ) );
101+
}
102+
103+
return sqmInsertSelectStatementCopy;
97104
}
98105

99106
@Override

hibernate-core/src/main/java/org/hibernate/query/sqm/tree/insert/SqmInsertValuesStatement.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public SqmInsertValuesStatement<T> copy(SqmCopyContext context) {
8686
valuesList.add( sqmValues.copy( context ) );
8787
}
8888
}
89-
return context.registerCopy(
89+
90+
final SqmInsertValuesStatement<T> sqmInsertValuesStatementCopy = context.registerCopy(
9091
this,
9192
new SqmInsertValuesStatement<>(
9293
nodeBuilder(),
@@ -95,10 +96,16 @@ public SqmInsertValuesStatement<T> copy(SqmCopyContext context) {
9596
copyCteStatements( context ),
9697
getTarget().copy( context ),
9798
copyInsertionTargetPaths( context ),
98-
getConflictClause() == null ? null : getConflictClause().copy( context ),
99+
null,
99100
valuesList
100101
)
101102
);
103+
104+
if ( getConflictClause() != null ) {
105+
sqmInsertValuesStatementCopy.setConflictClause( getConflictClause().copy( context ) );
106+
}
107+
108+
return sqmInsertValuesStatementCopy;
102109
}
103110

104111
public SqmInsertValuesStatement<T> copyWithoutValues(SqmCopyContext context) {

0 commit comments

Comments
 (0)