Skip to content

Commit 4bf817e

Browse files
committed
HHH-19895 Use alias for row value IN predicate values list emulation and correct DB2 z/OS misconfiguration
1 parent 5ce609f commit 4bf817e

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
@@ -237,4 +237,10 @@ public int rowIdSqlType() {
237237
public String getRowIdColumnString(String rowId) {
238238
return rowId( rowId ) + " rowid not null generated always";
239239
}
240+
241+
@Override
242+
public boolean supportsValuesList() {
243+
// DB2 z/OS has a VALUES statement, but that doesn't support multiple values
244+
return false;
245+
}
240246
}

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
@@ -7706,12 +7706,21 @@ public void visitInListPredicate(InListPredicate inListPredicate) {
77067706
else if ( !dialect.supportsRowValueConstructorSyntaxInInList() ) {
77077707
// Some DBs like Oracle support tuples only for the IN subquery predicate
77087708
if ( dialect.supportsRowValueConstructorSyntaxInInSubQuery() && dialect.supportsValuesList() ) {
7709+
final int tupleSize = lhsTuple.getExpressionType().getJdbcTypeCount();
77097710
inListPredicate.getTestExpression().accept( this );
77107711
if ( inListPredicate.isNegated() ) {
77117712
appendSql( " not" );
77127713
}
7713-
appendSql( " in (select * from (values" );
7714+
appendSql( " in (select" );
77147715
char separator = ' ';
7716+
for ( int i = 0; i < tupleSize; i++ ) {
7717+
appendSql( separator );
7718+
appendSql( "v_.c" );
7719+
appendSql( i );
7720+
separator = ',';
7721+
}
7722+
appendSql( " from (values" );
7723+
separator = ' ';
77157724
for ( Expression expression : listExpressions ) {
77167725
appendSql( separator );
77177726
appendSql( OPEN_PARENTHESIS );
@@ -7720,6 +7729,15 @@ else if ( !dialect.supportsRowValueConstructorSyntaxInInList() ) {
77207729
separator = ',';
77217730
}
77227731
appendSql( CLOSE_PARENTHESIS );
7732+
appendSql( " v_" );
7733+
separator = '(';
7734+
for ( int i = 0; i < tupleSize; i++ ) {
7735+
appendSql( separator );
7736+
appendSql( "c" );
7737+
appendSql( i );
7738+
separator = ',';
7739+
}
7740+
appendSql( CLOSE_PARENTHESIS );
77237741
appendSql( CLOSE_PARENTHESIS );
77247742
}
77257743
else if ( dialect.supportsRowValueConstructorSyntaxInInSubQuery() && dialect.supportsUnionAll() ) {

0 commit comments

Comments
 (0)