diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB297Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB297Dialect.java index 7715c62933..fd80bc4eeb 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB297Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB297Dialect.java @@ -6,6 +6,12 @@ */ package org.hibernate.dialect; +import org.hibernate.hql.spi.id.IdTableSupportStandardImpl; +import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy; +import org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy; +import org.hibernate.hql.spi.id.local.AfterUseAction; +import org.hibernate.hql.spi.id.local.LocalTemporaryTableBulkIdStrategy; + /** * An SQL dialect for DB2 9.7. * @@ -18,4 +24,29 @@ public class DB297Dialect extends DB2Dialect { // DB2 9.7 and later support "cross join" return " cross join "; } + + @Override + public MultiTableBulkIdStrategy getDefaultMultiTableBulkIdStrategy() { + // Starting in DB2 9.7, "real" global temporary tables that can be shared between sessions + // are supported; (obviously) data is not shared between sessions. + return new GlobalTemporaryTableBulkIdStrategy( + new IdTableSupportStandardImpl() { + @Override + public String generateIdTableName(String baseName) { + return super.generateIdTableName( baseName ); + } + + @Override + public String getCreateIdTableCommand() { + return "create global temporary table"; + } + + @Override + public String getCreateIdTableStatementOptions() { + return "not logged"; + } + }, + AfterUseAction.CLEAN + ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java index 5220c76015..4975397f80 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java @@ -35,6 +35,7 @@ import org.hibernate.hql.spi.id.IdTableSupportStandardImpl; import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy; import org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy; import org.hibernate.hql.spi.id.local.AfterUseAction; +import org.hibernate.hql.spi.id.local.LocalTemporaryTableBulkIdStrategy; import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.JdbcExceptionHelper; @@ -379,7 +380,10 @@ public class DB2Dialect extends Dialect { @Override public MultiTableBulkIdStrategy getDefaultMultiTableBulkIdStrategy() { - return new GlobalTemporaryTableBulkIdStrategy( + // Prior to DB2 9.7, "real" global temporary tables that can be shared between sessions + // are *not* supported; even though the DB2 command says to declare a "global" temp table + // Hibernate treats it as a "local" temp table. + return new LocalTemporaryTableBulkIdStrategy( new IdTableSupportStandardImpl() { @Override public String generateIdTableName(String baseName) { @@ -396,7 +400,8 @@ public class DB2Dialect extends Dialect { return "not logged"; } }, - AfterUseAction.CLEAN + AfterUseAction.DROP, + null ); }