For DB2, Hibernate creates a temporary table using: declare global temporary table session.HT_<baseName>(...) Starting in Hibernate ORM 5.0, Hibernate assumes this really is a "global" temporary table (created by GlobalTemporaryTableBulkIdStrategy) that can be created by the SessionFactory, and shared between different sessions. Unfortunately, for DB2, that temp table will only be defined for the particular session in which it is declared. This was not a problem prior to 5.0, because, up until 4.3, Hibernate treated temp tables as "local" to the current session, creating the temp tables as needed for each multi-table "bulk" operation, then dropping it (if necessary) after the statement was executed. Starting in DB2 9.7, "real" global temporary tables (that can be shared between sessions) are supported. The DDL for creating it should be: create global temporary table HT_<baseName>(...) The document has a good explanation of the differences. [2] [3] is specific to "declare global temporary table ...". [4] is specific to "create global temporary table ...". I believe we need 2 different implementations of Dialect#getDefaultMultiTableBulkIdStrategy for DB2:
- for pre-9.7, DB2Dialect needs return a MultiTableBulkIdStrategy that behaves like in 4.3;
- for 9.7 and later, DB297Dialect needs to return a GlobalTemporaryTableBulkIdStrategy that uses "create global temporary table HT_<baseName>" to create the temp table and does not prefix the table name with session..
[1] https://github.com/hibernate/hibernate-orm/blob/5.0/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java#L398-L419 [2] https://www.ibm.com/developerworks/data/library/techarticle/dm-0912globaltemptable/ [3] https://www.ibm.com/support/knowledgecenter/en/SSEPGG_9.7.0/com.ibm.db2.luw.sql.ref.doc/doc/r0003272.html [4] https://www.ibm.com/support/knowledgecenter/SSEPGG_9.7.0/com.ibm.db2.luw.wn.doc/doc/c0053706.html |