Skip to content

Commit 774969d

Browse files
committed
HHH-19314 StackOverflowException when using onConflict with createCriteriaInsertValues and createCriteriaInsertSelect
1 parent c2ccca2 commit 774969d

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
@@ -89,6 +89,10 @@ protected List<SqmPath<?>> copyInsertionTargetPaths(SqmCopyContext context) {
8989
}
9090
}
9191

92+
void setConflictClause(SqmConflictClause<T> conflictClause) {
93+
this.conflictClause = conflictClause;
94+
}
95+
9296
protected void verifyInsertTypesMatch(
9397
List<SqmPath<?>> insertionTargetPaths,
9498
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
@@ -54,7 +54,7 @@ private SqmConflictClause(
5454
this.insertStatement = insertStatement;
5555
this.excludedRoot = excludedRoot;
5656
this.constraintName = constraintName;
57-
this.constraintPaths = Collections.unmodifiableList( constraintPaths );
57+
this.constraintPaths = constraintPaths == null ? null : Collections.unmodifiableList( constraintPaths );
5858
this.updateAction = updateAction;
5959
}
6060

@@ -157,7 +157,7 @@ public SqmConflictClause<T> copy(SqmCopyContext context) {
157157
insertStatement.copy( context ),
158158
excludedRoot.copy( context ),
159159
constraintName,
160-
copyOf( constraintPaths, context ),
160+
constraintPaths == null ? null : copyOf( constraintPaths, context ),
161161
updateAction == null ? null : updateAction.copy( context )
162162
)
163163
);

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
@@ -77,19 +77,26 @@ public SqmInsertSelectStatement<T> copy(SqmCopyContext context) {
7777
if ( existing != null ) {
7878
return existing;
7979
}
80-
return context.registerCopy(
81-
this,
82-
new SqmInsertSelectStatement<>(
83-
nodeBuilder(),
84-
context.getQuerySource() == null ? getQuerySource() : context.getQuerySource(),
85-
copyParameters( context ),
86-
copyCteStatements( context ),
87-
getTarget().copy( context ),
88-
copyInsertionTargetPaths( context ),
89-
getConflictClause() == null ? null : getConflictClause().copy( context ),
90-
selectQueryPart.copy( context )
91-
)
80+
final SqmInsertSelectStatement<T> sqmInsertSelectStatementCopy = new SqmInsertSelectStatement<>(
81+
nodeBuilder(),
82+
context.getQuerySource() == null ? getQuerySource() : context.getQuerySource(),
83+
copyParameters( context ),
84+
copyCteStatements( context ),
85+
getTarget().copy( context ),
86+
null,
87+
null,
88+
selectQueryPart.copy( context )
9289
);
90+
91+
context.registerCopy( this, sqmInsertSelectStatementCopy );
92+
93+
sqmInsertSelectStatementCopy.setInsertionTargetPaths( copyInsertionTargetPaths( context ) );
94+
95+
if ( getConflictClause() != null ) {
96+
sqmInsertSelectStatementCopy.setConflictClause( getConflictClause().copy( context ) );
97+
}
98+
99+
return sqmInsertSelectStatementCopy;
93100
}
94101

95102
@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
@@ -82,7 +82,8 @@ public SqmInsertValuesStatement<T> copy(SqmCopyContext context) {
8282
valuesList.add( sqmValues.copy( context ) );
8383
}
8484
}
85-
return context.registerCopy(
85+
86+
final SqmInsertValuesStatement<T> sqmInsertValuesStatementCopy = context.registerCopy(
8687
this,
8788
new SqmInsertValuesStatement<>(
8889
nodeBuilder(),
@@ -91,10 +92,16 @@ public SqmInsertValuesStatement<T> copy(SqmCopyContext context) {
9192
copyCteStatements( context ),
9293
getTarget().copy( context ),
9394
copyInsertionTargetPaths( context ),
94-
getConflictClause() == null ? null : getConflictClause().copy( context ),
95+
null,
9596
valuesList
9697
)
9798
);
99+
100+
if ( getConflictClause() != null ) {
101+
sqmInsertValuesStatementCopy.setConflictClause( getConflictClause().copy( context ) );
102+
}
103+
104+
return sqmInsertValuesStatementCopy;
98105
}
99106

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

0 commit comments

Comments
 (0)