Skip to content

Commit

Permalink
[hibernate#1550] Fix Identity insert query for Db2
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideD committed Apr 4, 2023
1 parent 7e44e23 commit fa49ce5
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.concurrent.CompletionStage;

import org.hibernate.dialect.CockroachDialect;
import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.SQLServerDialect;
Expand Down Expand Up @@ -92,6 +93,11 @@ private static String createInsert(PreparedStatementDetails insertStatementDetai
}
return sql;
}
if ( dialect instanceof DB2Dialect ) {
// ORM query: select id from new table ( insert into IntegerTypeEntity values ( ))
// Correct : select id from new table ( insert into LongTypeEntity (id) values (default))
return insertStatementDetails.getSqlString().replace( " values ( ))", " (" + identifierColumnName + ") values (default))" );
}
return insertStatementDetails.getSqlString();
}

Expand Down

0 comments on commit fa49ce5

Please sign in to comment.