Skip to content

Commit 0d6eb60

Browse files
committed
HHH-19895 Use alias for row value IN predicate values list emulation and correct DB2 z/OS misconfiguration
1 parent afbc013 commit 0d6eb60

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2zLegacyDialect.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,10 @@ public int rowIdSqlType() {
251251
public String getRowIdColumnString(String rowId) {
252252
return rowId( rowId ) + " rowid not null generated always";
253253
}
254+
255+
@Override
256+
public boolean supportsValuesList() {
257+
// DB2 z/OS has a VALUES statement, but that doesn't support multiple values
258+
return false;
259+
}
254260
}

hibernate-core/src/main/java/org/hibernate/dialect/DB2zDialect.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,10 @@ public int rowIdSqlType() {
211211
public String getRowIdColumnString(String rowId) {
212212
return rowId( rowId ) + " rowid not null generated always";
213213
}
214+
215+
@Override
216+
public boolean supportsValuesList() {
217+
// DB2 z/OS has a VALUES statement, but that doesn't support multiple values
218+
return false;
219+
}
214220
}

hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7628,12 +7628,21 @@ public void visitInListPredicate(InListPredicate inListPredicate) {
76287628
else if ( !dialect.supportsRowValueConstructorSyntaxInInList() ) {
76297629
// Some DBs like Oracle support tuples only for the IN subquery predicate
76307630
if ( dialect.supportsRowValueConstructorSyntaxInInSubQuery() && dialect.supportsValuesList() ) {
7631+
final int tupleSize = lhsTuple.getExpressionType().getJdbcTypeCount();
76317632
inListPredicate.getTestExpression().accept( this );
76327633
if ( inListPredicate.isNegated() ) {
76337634
appendSql( " not" );
76347635
}
7635-
appendSql( " in (select * from (values" );
7636+
appendSql( " in (select" );
76367637
char separator = ' ';
7638+
for ( int i = 0; i < tupleSize; i++ ) {
7639+
appendSql( separator );
7640+
appendSql( "v_.c" );
7641+
appendSql( i );
7642+
separator = ',';
7643+
}
7644+
appendSql( " from (values" );
7645+
separator = ' ';
76377646
for ( Expression expression : listExpressions ) {
76387647
appendSql( separator );
76397648
appendSql( OPEN_PARENTHESIS );
@@ -7642,6 +7651,15 @@ else if ( !dialect.supportsRowValueConstructorSyntaxInInList() ) {
76427651
separator = ',';
76437652
}
76447653
appendSql( CLOSE_PARENTHESIS );
7654+
appendSql( " v_" );
7655+
separator = '(';
7656+
for ( int i = 0; i < tupleSize; i++ ) {
7657+
appendSql( separator );
7658+
appendSql( "c" );
7659+
appendSql( i );
7660+
separator = ',';
7661+
}
7662+
appendSql( CLOSE_PARENTHESIS );
76457663
appendSql( CLOSE_PARENTHESIS );
76467664
}
76477665
else if ( dialect.supportsRowValueConstructorSyntaxInInSubQuery() && dialect.supportsUnionAll() ) {

0 commit comments

Comments
 (0)