Skip to content

Commit 3c5faf5

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

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
@@ -233,4 +233,10 @@ public int rowIdSqlType() {
233233
public String getRowIdColumnString(String rowId) {
234234
return rowId( rowId ) + " rowid not null generated always";
235235
}
236+
237+
@Override
238+
public boolean supportsValuesList() {
239+
// DB2 z/OS has a VALUES statement, but that doesn't support multiple values
240+
return false;
241+
}
236242
}

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

0 commit comments

Comments
 (0)