From 86abe7fd4fdbcc4d4342498ff0f1e59a35d1fb84 Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Thu, 19 Jul 2018 09:54:02 -0400 Subject: [PATCH] HHH-12753 - Fix Nationalized CLOB test failures on DB2. Force column read/write to use non-nationalized driver methods since the driver does not implement the nationalized equivalents. (cherry picked from commit 005d5b7c748c4c03afddae43a6fc2299869ab0f9) --- .../org/hibernate/dialect/DB297Dialect.java | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) 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 314f1eba2d..44730c84c6 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB297Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB297Dialect.java @@ -6,14 +6,17 @@ */ package org.hibernate.dialect; +import java.sql.Types; + import org.hibernate.dialect.function.DB2SubstringFunction; -import org.hibernate.dialect.function.StandardSQLFunction; 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.type.StandardBasicTypes; +import org.hibernate.type.descriptor.sql.CharTypeDescriptor; +import org.hibernate.type.descriptor.sql.ClobTypeDescriptor; +import org.hibernate.type.descriptor.sql.SqlTypeDescriptor; +import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor; /** * An SQL dialect for DB2 9.7. @@ -57,4 +60,37 @@ public class DB297Dialect extends DB2Dialect { AfterUseAction.CLEAN ); } + + @Override + protected SqlTypeDescriptor getSqlTypeDescriptorOverride(int sqlCode) { + // See HHH-12753 + // It seems that DB2's JDBC 4.0 support as of 9.5 does not support the N-variant methods like + // NClob or NString. Therefore here we overwrite the sql type descriptors to use the non-N variants + // which are supported. + switch ( sqlCode ) { + case Types.NCHAR: + return CharTypeDescriptor.INSTANCE; + + case Types.NCLOB: + if ( useInputStreamToInsertBlob() ) { + return ClobTypeDescriptor.STREAM_BINDING; + } + else { + return ClobTypeDescriptor.CLOB_BINDING; + } + + case Types.NVARCHAR: + return VarcharTypeDescriptor.INSTANCE; + + default: + return super.getSqlTypeDescriptorOverride( sqlCode ); + } + } + + @Override + public boolean canCreateSchema() { + // this seems to only be a problem in QE where schema management is disabled. + // should we keep this? + return false; + } }