From 755c93c9f1e982bf88798fda1b6b25f9fcb7b879 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Sat, 29 Jun 2024 08:52:56 +0200 Subject: [PATCH] HHH-18314 NCHAR,NVARCHAR,NCLOB on Db2 1. Db2 driver now supports setNString() and friends 2. Hibernate SchemaValidator + SchemaMigrator now consider NUMERIC and DECIMAL equivalent We may therefore roll back HHH-12753 and HHH-12827 respectively. Signed-off-by: Gavin King --- .../community/dialect/DB2LegacyDialect.java | 5 ----- .../community/dialect/DerbyLegacyDialect.java | 2 -- .../java/org/hibernate/dialect/DB2Dialect.java | 16 ---------------- .../java/org/hibernate/dialect/DerbyDialect.java | 4 ---- .../type/descriptor/jdbc/DecimalJdbcType.java | 1 - .../orm/test/mapping/basic/NationalizedTest.java | 4 ++-- .../basic/StringNationalizedMappingTests.java | 8 ++++++-- 7 files changed, 8 insertions(+), 32 deletions(-) diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2LegacyDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2LegacyDialect.java index c0cebad8c7..08b45c6e15 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2LegacyDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2LegacyDialect.java @@ -95,7 +95,6 @@ import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.java.PrimitiveByteArrayJavaType; import org.hibernate.type.descriptor.jdbc.CharJdbcType; import org.hibernate.type.descriptor.jdbc.ClobJdbcType; -import org.hibernate.type.descriptor.jdbc.DecimalJdbcType; import org.hibernate.type.descriptor.jdbc.InstantJdbcType; import org.hibernate.type.descriptor.jdbc.LocalDateJdbcType; import org.hibernate.type.descriptor.jdbc.LocalDateTimeJdbcType; @@ -889,9 +888,6 @@ public class DB2LegacyDialect extends Dialect { jdbcTypeRegistry.addDescriptor( Types.BOOLEAN, SmallIntJdbcType.INSTANCE ); // Binary literals were only added in 11. See https://www.ibm.com/support/knowledgecenter/SSEPGG_11.1.0/com.ibm.db2.luw.sql.ref.doc/doc/r0000731.html#d79816e393 jdbcTypeRegistry.addDescriptor( Types.VARBINARY, VarbinaryJdbcType.INSTANCE_WITHOUT_LITERALS ); - if ( getDB2Version().isBefore( 9, 7 ) ) { - jdbcTypeRegistry.addDescriptor( Types.NUMERIC, DecimalJdbcType.INSTANCE ); - } } // See HHH-12753 // It seems that DB2's JDBC 4.0 support as of 9.5 does not @@ -901,7 +897,6 @@ public class DB2LegacyDialect extends Dialect { jdbcTypeRegistry.addDescriptor( Types.NCHAR, CharJdbcType.INSTANCE ); jdbcTypeRegistry.addDescriptor( Types.NCLOB, ClobJdbcType.STREAM_BINDING ); jdbcTypeRegistry.addDescriptor( Types.NVARCHAR, VarcharJdbcType.INSTANCE ); - jdbcTypeRegistry.addDescriptor( Types.NUMERIC, DecimalJdbcType.INSTANCE ); jdbcTypeRegistry.addDescriptor( XmlJdbcType.INSTANCE ); jdbcTypeRegistry.addDescriptor( DB2StructJdbcType.INSTANCE ); diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DerbyLegacyDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DerbyLegacyDialect.java index 70e098ece4..84039bec3a 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DerbyLegacyDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DerbyLegacyDialect.java @@ -73,7 +73,6 @@ import org.hibernate.type.BasicTypeRegistry; import org.hibernate.type.JavaObjectType; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.descriptor.java.BigDecimalJavaType; -import org.hibernate.type.descriptor.jdbc.DecimalJdbcType; import org.hibernate.type.descriptor.jdbc.ObjectNullResolvingJdbcType; import org.hibernate.type.descriptor.jdbc.SmallIntJdbcType; import org.hibernate.type.descriptor.jdbc.TimestampJdbcType; @@ -686,7 +685,6 @@ public class DerbyLegacyDialect extends Dialect { if ( getVersion().isBefore( 10, 7 ) ) { jdbcTypeRegistry.addDescriptor( Types.BOOLEAN, SmallIntJdbcType.INSTANCE ); } - jdbcTypeRegistry.addDescriptor( Types.NUMERIC, DecimalJdbcType.INSTANCE ); jdbcTypeRegistry.addDescriptor( Types.TIMESTAMP_WITH_TIMEZONE, TimestampJdbcType.INSTANCE ); // Derby requires a custom binder for binding untyped nulls that resolves the type through the statement 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 070091a266..5b04e87c3e 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java @@ -84,9 +84,6 @@ import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.descriptor.ValueExtractor; import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.java.PrimitiveByteArrayJavaType; -import org.hibernate.type.descriptor.jdbc.CharJdbcType; -import org.hibernate.type.descriptor.jdbc.ClobJdbcType; -import org.hibernate.type.descriptor.jdbc.DecimalJdbcType; import org.hibernate.type.descriptor.jdbc.InstantJdbcType; import org.hibernate.type.descriptor.jdbc.LocalDateJdbcType; import org.hibernate.type.descriptor.jdbc.LocalDateTimeJdbcType; @@ -96,7 +93,6 @@ import org.hibernate.type.descriptor.jdbc.OffsetDateTimeJdbcType; import org.hibernate.type.descriptor.jdbc.OffsetTimeJdbcType; import org.hibernate.type.descriptor.jdbc.SmallIntJdbcType; import org.hibernate.type.descriptor.jdbc.VarbinaryJdbcType; -import org.hibernate.type.descriptor.jdbc.VarcharJdbcType; import org.hibernate.type.descriptor.jdbc.XmlJdbcType; import org.hibernate.type.descriptor.jdbc.ZonedDateTimeJdbcType; import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry; @@ -984,19 +980,7 @@ public class DB2Dialect extends Dialect { jdbcTypeRegistry.addDescriptor( Types.BOOLEAN, SmallIntJdbcType.INSTANCE ); // Binary literals were only added in 11. See https://www.ibm.com/support/knowledgecenter/SSEPGG_11.1.0/com.ibm.db2.luw.sql.ref.doc/doc/r0000731.html#d79816e393 jdbcTypeRegistry.addDescriptor( Types.VARBINARY, VarbinaryJdbcType.INSTANCE_WITHOUT_LITERALS ); - if ( getDB2Version().isBefore( 9, 7 ) ) { - jdbcTypeRegistry.addDescriptor( Types.NUMERIC, DecimalJdbcType.INSTANCE ); - } } - // 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. - jdbcTypeRegistry.addDescriptor( Types.NCHAR, CharJdbcType.INSTANCE ); - jdbcTypeRegistry.addDescriptor( Types.NCLOB, ClobJdbcType.STREAM_BINDING ); - jdbcTypeRegistry.addDescriptor( Types.NVARCHAR, VarcharJdbcType.INSTANCE ); - jdbcTypeRegistry.addDescriptor( Types.NUMERIC, DecimalJdbcType.INSTANCE ); jdbcTypeRegistry.addDescriptor( XmlJdbcType.INSTANCE ); jdbcTypeRegistry.addDescriptor( DB2StructJdbcType.INSTANCE ); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java index d4a5e9ff15..47641c1d79 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java @@ -68,7 +68,6 @@ import org.hibernate.type.BasicTypeRegistry; import org.hibernate.type.JavaObjectType; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.descriptor.java.BigDecimalJavaType; -import org.hibernate.type.descriptor.jdbc.DecimalJdbcType; import org.hibernate.type.descriptor.jdbc.ObjectNullResolvingJdbcType; import org.hibernate.type.descriptor.jdbc.TimestampJdbcType; import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry; @@ -78,8 +77,6 @@ import org.hibernate.type.spi.TypeConfiguration; import jakarta.persistence.TemporalType; -import static org.hibernate.query.sqm.produce.function.FunctionParameterType.INTEGER; -import static org.hibernate.query.sqm.produce.function.FunctionParameterType.STRING; import static org.hibernate.type.SqlTypes.BINARY; import static org.hibernate.type.SqlTypes.BLOB; import static org.hibernate.type.SqlTypes.CHAR; @@ -663,7 +660,6 @@ public class DerbyDialect extends Dialect { super.contributeTypes( typeContributions, serviceRegistry ); final JdbcTypeRegistry jdbcTypeRegistry = typeContributions.getTypeConfiguration() .getJdbcTypeRegistry(); - jdbcTypeRegistry.addDescriptor( Types.NUMERIC, DecimalJdbcType.INSTANCE ); jdbcTypeRegistry.addDescriptor( Types.TIMESTAMP_WITH_TIMEZONE, TimestampJdbcType.INSTANCE ); // Derby requires a custom binder for binding untyped nulls that resolves the type through the statement diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/DecimalJdbcType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/DecimalJdbcType.java index 1905e25000..6494c1d653 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/DecimalJdbcType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/DecimalJdbcType.java @@ -16,7 +16,6 @@ import java.sql.Types; import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.ValueExtractor; import org.hibernate.type.descriptor.WrapperOptions; -import org.hibernate.type.descriptor.java.BasicJavaType; import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.jdbc.internal.JdbcLiteralFormatterNumericData; import org.hibernate.type.spi.TypeConfiguration; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/NationalizedTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/NationalizedTest.java index fc12c43657..c9c1976652 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/NationalizedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/NationalizedTest.java @@ -36,7 +36,7 @@ public class NationalizedTest extends BaseEntityManagerFunctionalTestCase { final Product product = new Product(); product.setId(1); product.setName("Mobile phone"); - product.setWarranty("My product warranty"); + product.setWarranty("My product®™ warranty 😍"); entityManager.persist(product); //end::basic-nationalized-persist-example[] @@ -46,7 +46,7 @@ public class NationalizedTest extends BaseEntityManagerFunctionalTestCase { doInJPA(this::entityManagerFactory, entityManager -> { Product product = entityManager.find(Product.class, productId); - assertEquals("My product warranty", product.getWarranty()); + assertEquals("My product®™ warranty 😍", product.getWarranty()); }); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/StringNationalizedMappingTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/StringNationalizedMappingTests.java index 34c38bdbab..1aa86adc1a 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/StringNationalizedMappingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/StringNationalizedMappingTests.java @@ -69,10 +69,14 @@ public class StringNationalizedMappingTests { // and try to use the mapping scope.inTransaction( - (session) -> session.persist(new EntityOfStrings(1, "nstring", "nclob")) + (session) -> session.persist(new EntityOfStrings(1, "nstring 🦑", "nclob 🦀")) ); scope.inTransaction( - (session) -> session.get(EntityOfStrings.class, 1) + (session) -> { + EntityOfStrings entity = session.get(EntityOfStrings.class, 1); + assertThat( entity.nstring, is("nstring 🦑") ); + assertThat( entity.nclobString, is("nclob 🦀") ); + } ); }