diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2LegacySqlAstTranslator.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2LegacySqlAstTranslator.java index 015bc1e906..e5d5aee4ab 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2LegacySqlAstTranslator.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2LegacySqlAstTranslator.java @@ -12,6 +12,7 @@ import java.util.function.Consumer; import org.hibernate.LockMode; import org.hibernate.dialect.DatabaseVersion; import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.metamodel.mapping.JdbcMappingContainer; import org.hibernate.query.sqm.ComparisonOperator; import org.hibernate.query.sqm.FetchClauseType; import org.hibernate.sql.ast.SqlAstNodeRenderingMode; @@ -40,6 +41,7 @@ import org.hibernate.sql.ast.tree.select.QuerySpec; import org.hibernate.sql.ast.tree.select.SelectStatement; import org.hibernate.sql.ast.tree.update.UpdateStatement; import org.hibernate.sql.exec.spi.JdbcOperation; +import org.hibernate.type.SqlTypes; /** * A SQL AST translator for DB2. @@ -376,10 +378,79 @@ public class DB2LegacySqlAstTranslator extends Abstract renderComparisonStandard( lhs, operator, rhs ); } else { + final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType(); + if ( lhsExpressionType != null + && lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) { + // In SQL Server, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose + switch ( operator ) { + case DISTINCT_FROM: + appendSql( "decode(" ); + appendSql( "xmlserialize(" ); + lhs.accept( this ); + appendSql( " as varchar(32672))" ); + appendSql( ',' ); + appendSql( "xmlserialize(" ); + rhs.accept( this ); + appendSql( " as varchar(32672))" ); + appendSql( ",0,1)=1" ); + return; + case NOT_DISTINCT_FROM: + appendSql( "decode(" ); + appendSql( "xmlserialize(" ); + lhs.accept( this ); + appendSql( " as varchar(32672))" ); + appendSql( ',' ); + appendSql( "xmlserialize(" ); + rhs.accept( this ); + appendSql( " as varchar(32672))" ); + appendSql( ",0,1)=0" ); + return; + case EQUAL: + case NOT_EQUAL: + appendSql( "xmlserialize(" ); + lhs.accept( this ); + appendSql( " as varchar(32672))" ); + appendSql( operator.sqlText() ); + appendSql( "xmlserialize(" ); + rhs.accept( this ); + appendSql( " as varchar(32672))" ); + return; + default: + // Fall through + break; + } + } renderComparisonEmulateDecode( lhs, operator, rhs ); } } + @Override + protected void renderComparisonStandard(Expression lhs, ComparisonOperator operator, Expression rhs) { + final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType(); + if ( lhsExpressionType != null + && lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) { + // In SQL Server, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose + switch ( operator ) { + case EQUAL: + case NOT_DISTINCT_FROM: + case NOT_EQUAL: + case DISTINCT_FROM: + appendSql( "xmlserialize(" ); + lhs.accept( this ); + appendSql( " as varchar(32672))" ); + appendSql( operator.sqlText() ); + appendSql( "xmlserialize(" ); + rhs.accept( this ); + appendSql( " as varchar(32672))" ); + return; + default: + // Fall through + break; + } + } + super.renderComparisonStandard( lhs, operator, rhs ); + } + @Override protected void renderSelectExpression(Expression expression) { renderSelectExpressionWithCastedOrInlinedPlainParameters( expression ); 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 29a96bebef..09d808458b 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 @@ -176,49 +176,42 @@ public class DerbyLegacyDialect extends Dialect { super.registerColumnTypes( typeContributions, serviceRegistry ); final DdlTypeRegistry ddlTypeRegistry = typeContributions.getTypeConfiguration().getDdlTypeRegistry(); - //long varchar is the right type to use for lengths between 32_672 and 32_700 - int maxLongVarcharLength = 32_700; + int varcharDdlTypeCapacity = 32_672; ddlTypeRegistry.addDescriptor( - CapacityDependentDdlType.builder( VARBINARY, columnType( BLOB ), columnType( VARBINARY ), this ) - .withTypeCapacity( getMaxVarbinaryLength(), columnType( VARBINARY ) ) - .withTypeCapacity( maxLongVarcharLength, columnType( LONG32VARBINARY ) ) + CapacityDependentDdlType.builder( VARBINARY, columnType( LONG32VARBINARY ), columnType( VARBINARY ), this ) + .withTypeCapacity( varcharDdlTypeCapacity, columnType( VARBINARY ) ) .build() ); ddlTypeRegistry.addDescriptor( - CapacityDependentDdlType.builder( VARCHAR, columnType( CLOB ), columnType( VARCHAR ), this ) - .withTypeCapacity( getMaxVarcharLength(), columnType( VARCHAR ) ) - .withTypeCapacity( maxLongVarcharLength, columnType( LONG32VARCHAR ) ) + CapacityDependentDdlType.builder( VARCHAR, columnType( LONG32VARCHAR ), columnType( VARCHAR ), this ) + .withTypeCapacity( varcharDdlTypeCapacity, columnType( VARCHAR ) ) .build() ); ddlTypeRegistry.addDescriptor( - CapacityDependentDdlType.builder( NVARCHAR, columnType( CLOB ), columnType( NVARCHAR ), this ) - .withTypeCapacity( getMaxVarcharLength(), columnType( NVARCHAR ) ) - .withTypeCapacity( maxLongVarcharLength, columnType( LONG32VARCHAR ) ) + CapacityDependentDdlType.builder( NVARCHAR, columnType( LONG32VARCHAR ), columnType( NVARCHAR ), this ) + .withTypeCapacity( varcharDdlTypeCapacity, columnType( NVARCHAR ) ) .build() ); ddlTypeRegistry.addDescriptor( - CapacityDependentDdlType.builder( BINARY, columnType( BLOB ), columnType( VARBINARY ), this ) + CapacityDependentDdlType.builder( BINARY, columnType( LONG32VARBINARY ), columnType( VARBINARY ), this ) .withTypeCapacity( 254, "char($l) for bit data" ) - .withTypeCapacity( getMaxVarbinaryLength(), columnType( VARBINARY ) ) - .withTypeCapacity( maxLongVarcharLength, columnType( LONG32VARBINARY ) ) + .withTypeCapacity( varcharDdlTypeCapacity, columnType( VARBINARY ) ) .build() ); // This is the maximum size for the CHAR datatype on Derby ddlTypeRegistry.addDescriptor( - CapacityDependentDdlType.builder( CHAR, columnType( CLOB ), columnType( CHAR ), this ) + CapacityDependentDdlType.builder( CHAR, columnType( LONG32VARCHAR ), columnType( CHAR ), this ) .withTypeCapacity( 254, columnType( CHAR ) ) .withTypeCapacity( getMaxVarcharLength(), columnType( VARCHAR ) ) - .withTypeCapacity( maxLongVarcharLength, columnType( LONG32VARCHAR ) ) .build() ); ddlTypeRegistry.addDescriptor( - CapacityDependentDdlType.builder( NCHAR, columnType( CLOB ), columnType( NCHAR ), this ) + CapacityDependentDdlType.builder( NCHAR, columnType( LONG32NVARCHAR ), columnType( NCHAR ), this ) .withTypeCapacity( 254, columnType( NCHAR ) ) .withTypeCapacity( getMaxVarcharLength(), columnType( NVARCHAR ) ) - .withTypeCapacity( maxLongVarcharLength, columnType( LONG32NVARCHAR ) ) .build() ); } @@ -228,6 +221,11 @@ public class DerbyLegacyDialect extends Dialect { return 32_672; } + @Override + public int getMaxVarcharCapacity() { + return 32_700; + } + @Override public int getDefaultDecimalPrecision() { //this is the maximum allowed in Derby diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MySQLLegacyDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MySQLLegacyDialect.java index d536990e28..86c17dbb93 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MySQLLegacyDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MySQLLegacyDialect.java @@ -11,7 +11,6 @@ import java.sql.DatabaseMetaData; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; -import java.util.Arrays; import org.hibernate.LockOptions; import org.hibernate.PessimisticLockException; @@ -245,6 +244,12 @@ public class MySQLLegacyDialect extends Dialect { } } + @Override + public boolean useMaterializedLobWhenCapacityExceeded() { + // MySQL has no real concept of LOBs, so we can just use longtext/longblob with the materialized JDBC APIs + return false; + } + @Override protected String castType(int sqlTypeCode) { switch ( sqlTypeCode ) { @@ -337,7 +342,7 @@ public class MySQLLegacyDialect extends Dialect { ) .withTypeCapacity( getMaxVarbinaryLength(), "varbinary($l)" ) .withTypeCapacity( maxMediumLobLen, "mediumblob" ); - if ( getMaxVarcharLength() < maxLobLen ) { + if ( getMaxVarbinaryLength() < maxLobLen ) { varbinaryBuilder.withTypeCapacity( maxLobLen, "blob" ); } ddlTypeRegistry.addDescriptor( varbinaryBuilder.build() ); diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/OracleLegacySqlAstTranslator.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/OracleLegacySqlAstTranslator.java index d906ae8608..670a795292 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/OracleLegacySqlAstTranslator.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/OracleLegacySqlAstTranslator.java @@ -380,7 +380,7 @@ public class OracleLegacySqlAstTranslator extends Abstr renderComparisonEmulateDecode( lhs, operator, rhs ); return; } - switch ( lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getJdbcTypeCode() ) { + switch ( lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() ) { case SqlTypes.SQLXML: // In Oracle, XMLTYPE is not "comparable", so we have to use the xmldiff function for this purpose switch ( operator ) { @@ -402,8 +402,11 @@ public class OracleLegacySqlAstTranslator extends Abstr rhs.accept( this ); appendSql( "),'/*[local-name()=''xdiff'']/*')" ); break; + case SqlTypes.CLOB: + case SqlTypes.NCLOB: case SqlTypes.BLOB: - // In Oracle, BLOB types are not "comparable", so we have to use the dbms_lob.compare function for this purpose + // In Oracle, BLOB, CLOB and NCLOB types are not "comparable", + // so we have to use the dbms_lob.compare function for this purpose switch ( operator ) { case EQUAL: appendSql( "0=" ); diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacyDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacyDialect.java index 248bb57c93..182bcf7ffa 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacyDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacyDialect.java @@ -278,6 +278,12 @@ public class PostgreSQLLegacyDialect extends Dialect { return 10_485_760; } + @Override + public int getMaxVarcharCapacity() { + // 1GB according to PostgreSQL docs + return 1_073_741_824; + } + @Override public int getMaxVarbinaryLength() { //postgres has no varbinary-like type @@ -1018,6 +1024,13 @@ public class PostgreSQLLegacyDialect extends Dialect { return false; } + @Override + public boolean supportsMaterializedLobAccess() { + // Prefer using text and bytea over oid (LOB), because oid is very restricted. + // If someone really wants a type bigger than 1GB, they should ask for it by using @Lob explicitly + return false; + } + @Override public boolean supportsTemporalLiteralOffset() { return true; diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacySqlAstTranslator.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacySqlAstTranslator.java index 176fbe7a13..634a66e31b 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacySqlAstTranslator.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacySqlAstTranslator.java @@ -8,6 +8,7 @@ package org.hibernate.community.dialect; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.mapping.JdbcMappingContainer; +import org.hibernate.query.sqm.ComparisonOperator; import org.hibernate.query.sqm.FetchClauseType; import org.hibernate.sql.ast.spi.AbstractSqlAstTranslator; import org.hibernate.sql.ast.tree.Statement; @@ -25,6 +26,7 @@ import org.hibernate.sql.ast.tree.select.QueryPart; import org.hibernate.sql.ast.tree.select.QuerySpec; import org.hibernate.sql.exec.spi.JdbcOperation; import org.hibernate.sql.model.internal.TableInsertStandard; +import org.hibernate.type.SqlTypes; /** * A SQL AST translator for PostgreSQL. @@ -48,6 +50,33 @@ public class PostgreSQLLegacySqlAstTranslator extends A expression.accept( this ); } + @Override + protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) { + final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType(); + if ( lhsExpressionType != null + && lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) { + // In PostgreSQL, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose + switch ( operator ) { + case EQUAL: + case NOT_DISTINCT_FROM: + case NOT_EQUAL: + case DISTINCT_FROM: + appendSql( "cast(" ); + lhs.accept( this ); + appendSql( " as text)" ); + appendSql( operator.sqlText() ); + appendSql( "cast(" ); + rhs.accept( this ); + appendSql( " as text)" ); + return; + default: + // Fall through + break; + } + } + renderComparisonStandard( lhs, operator, rhs ); + } + @Override public void visitBooleanExpressionPredicate(BooleanExpressionPredicate booleanExpressionPredicate) { final boolean isNegated = booleanExpressionPredicate.isNegated(); diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLServerLegacySqlAstTranslator.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLServerLegacySqlAstTranslator.java index 9fb72030d4..4d3d1c37ff 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLServerLegacySqlAstTranslator.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLServerLegacySqlAstTranslator.java @@ -11,6 +11,7 @@ import java.util.List; import org.hibernate.LockMode; import org.hibernate.LockOptions; import org.hibernate.dialect.DatabaseVersion; +import org.hibernate.metamodel.mapping.JdbcMappingContainer; import org.hibernate.query.sqm.FetchClauseType; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.query.sqm.ComparisonOperator; @@ -37,6 +38,7 @@ import org.hibernate.sql.ast.tree.select.QuerySpec; import org.hibernate.sql.ast.tree.select.SelectClause; import org.hibernate.sql.ast.tree.select.SortSpecification; import org.hibernate.sql.exec.spi.JdbcOperation; +import org.hibernate.type.SqlTypes; /** * A SQL AST translator for SQL Server. @@ -394,6 +396,28 @@ public class SQLServerLegacySqlAstTranslator extends Ab @Override protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) { + final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType(); + if ( lhsExpressionType != null + && lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) { + // In SQL Server, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose + switch ( operator ) { + case EQUAL: + case NOT_DISTINCT_FROM: + case NOT_EQUAL: + case DISTINCT_FROM: + appendSql( "cast(" ); + lhs.accept( this ); + appendSql( " as nvarchar(max))" ); + appendSql( operator.sqlText() ); + appendSql( "cast(" ); + rhs.accept( this ); + appendSql( " as nvarchar(max))" ); + return; + default: + // Fall through + break; + } + } renderComparisonEmulateIntersect( lhs, operator, rhs ); } diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/JdbcTypeRegistration.java b/hibernate-core/src/main/java/org/hibernate/annotations/JdbcTypeRegistration.java index 63a8bb3816..c3898a6f4a 100644 --- a/hibernate-core/src/main/java/org/hibernate/annotations/JdbcTypeRegistration.java +++ b/hibernate-core/src/main/java/org/hibernate/annotations/JdbcTypeRegistration.java @@ -48,7 +48,7 @@ public @interface JdbcTypeRegistration { * The type-code under which to register this descriptor. Can either add a new descriptor * or override an existing one. * - * By default we will use {@link JdbcType#getJdbcTypeCode} + * By default we will use {@link JdbcType#getDefaultSqlTypeCode()} */ int registrationCode() default Integer.MIN_VALUE; } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotationBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotationBinder.java index 5cd46162d8..d07f5db0a2 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotationBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotationBinder.java @@ -626,7 +626,7 @@ public final class AnnotationBinder { final Class jdbcTypeClass = annotation.value(); final JdbcType jdbcType = managedBeanRegistry.getBean( jdbcTypeClass ).getBeanInstance(); final int typeCode = annotation.registrationCode() == Integer.MIN_VALUE - ? jdbcType.getJdbcTypeCode() + ? jdbcType.getDefaultSqlTypeCode() : annotation.registrationCode(); context.getMetadataCollector().addJdbcTypeRegistration( typeCode, jdbcType ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/VersionResolution.java b/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/VersionResolution.java index aceee15d67..963c6cf2f6 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/VersionResolution.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/VersionResolution.java @@ -96,7 +96,7 @@ public class VersionResolution implements BasicValue.Resolution { final BasicType basicType = typeConfiguration.getBasicTypeRegistry().resolve( jtd, recommendedJdbcType ); final BasicType legacyType = typeConfiguration.getBasicTypeRegistry().getRegisteredType( jtd.getJavaType() ); - assert legacyType.getJdbcType().getJdbcTypeCode() == recommendedJdbcType.getJdbcTypeCode(); + assert legacyType.getJdbcType().getDefaultSqlTypeCode() == recommendedJdbcType.getDefaultSqlTypeCode(); return new VersionResolution<>( jtd, recommendedJdbcType, basicType, legacyType ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java index bed697a1db..bc3f47ccae 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java @@ -1911,7 +1911,7 @@ public class ModelBinder { .getBasicTypeRegistry() .getRegisteredType( value.getTypeName() ); if ( basicType instanceof AbstractSingleColumnStandardBasicType ) { - if ( isLob( basicType.getJdbcType().getJdbcTypeCode(), null ) ) { + if ( isLob( basicType.getJdbcType().getDdlTypeCode(), null ) ) { value.makeLob(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2SqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2SqlAstTranslator.java index be47d61c18..58dcd20b94 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2SqlAstTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2SqlAstTranslator.java @@ -11,6 +11,7 @@ import java.util.function.Consumer; import org.hibernate.LockMode; import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.metamodel.mapping.JdbcMappingContainer; import org.hibernate.query.sqm.ComparisonOperator; import org.hibernate.query.sqm.FetchClauseType; import org.hibernate.sql.ast.SqlAstNodeRenderingMode; @@ -40,6 +41,7 @@ import org.hibernate.sql.ast.tree.select.SelectStatement; import org.hibernate.sql.ast.tree.update.UpdateStatement; import org.hibernate.sql.exec.spi.JdbcOperation; import org.hibernate.sql.model.internal.TableInsertStandard; +import org.hibernate.type.SqlTypes; import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty; import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty; @@ -400,10 +402,79 @@ public class DB2SqlAstTranslator extends AbstractSqlAst renderComparisonStandard( lhs, operator, rhs ); } else { + final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType(); + if ( lhsExpressionType != null + && lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) { + // In SQL Server, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose + switch ( operator ) { + case DISTINCT_FROM: + appendSql( "decode(" ); + appendSql( "xmlserialize(" ); + lhs.accept( this ); + appendSql( " as varchar(32672))" ); + appendSql( ',' ); + appendSql( "xmlserialize(" ); + rhs.accept( this ); + appendSql( " as varchar(32672))" ); + appendSql( ",0,1)=1" ); + return; + case NOT_DISTINCT_FROM: + appendSql( "decode(" ); + appendSql( "xmlserialize(" ); + lhs.accept( this ); + appendSql( " as varchar(32672))" ); + appendSql( ',' ); + appendSql( "xmlserialize(" ); + rhs.accept( this ); + appendSql( " as varchar(32672))" ); + appendSql( ",0,1)=0" ); + return; + case EQUAL: + case NOT_EQUAL: + appendSql( "xmlserialize(" ); + lhs.accept( this ); + appendSql( " as varchar(32672))" ); + appendSql( operator.sqlText() ); + appendSql( "xmlserialize(" ); + rhs.accept( this ); + appendSql( " as varchar(32672))" ); + return; + default: + // Fall through + break; + } + } renderComparisonEmulateDecode( lhs, operator, rhs ); } } + @Override + protected void renderComparisonStandard(Expression lhs, ComparisonOperator operator, Expression rhs) { + final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType(); + if ( lhsExpressionType != null + && lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) { + // In SQL Server, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose + switch ( operator ) { + case EQUAL: + case NOT_DISTINCT_FROM: + case NOT_EQUAL: + case DISTINCT_FROM: + appendSql( "xmlserialize(" ); + lhs.accept( this ); + appendSql( " as varchar(32672))" ); + appendSql( operator.sqlText() ); + appendSql( "xmlserialize(" ); + rhs.accept( this ); + appendSql( " as varchar(32672))" ); + return; + default: + // Fall through + break; + } + } + super.renderComparisonStandard( lhs, operator, rhs ); + } + @Override protected void renderSelectExpression(Expression expression) { renderSelectExpressionWithCastedOrInlinedPlainParameters( expression ); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java index c921cad70c..b6a85beae4 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java @@ -4279,13 +4279,13 @@ public abstract class Dialect implements ConversionContext { Integer scale, Long length) { final Size size = new Size(); - int jdbcTypeCode = jdbcType.getDefaultSqlTypeCode(); + final int ddlTypeCode = jdbcType.getDdlTypeCode(); // Set the explicit length to null if we encounter the JPA default 255 if ( length != null && length == Size.DEFAULT_LENGTH ) { length = null; } - switch ( jdbcTypeCode ) { + switch ( ddlTypeCode ) { case SqlTypes.BIT: case SqlTypes.CHAR: case SqlTypes.NCHAR: diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java index c17e529afa..8d3a9b1d2b 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java @@ -123,7 +123,7 @@ public class MySQLDialect extends Dialect { Integer precision, Integer scale, Long length) { - switch ( jdbcType.getDefaultSqlTypeCode() ) { + switch ( jdbcType.getDdlTypeCode() ) { case Types.BIT: // MySQL allows BIT with a length up to 64 (less the default length 255) if ( length != null ) { @@ -310,9 +310,9 @@ public class MySQLDialect extends Dialect { "char", this ) - .withTypeCapacity( getVarcharDdlTypeCapacity(), "varchar($l)" ) + .withTypeCapacity( getMaxVarcharLength(), "varchar($l)" ) .withTypeCapacity( maxMediumLobLen, "mediumtext" ); - if ( getVarcharDdlTypeCapacity() < maxLobLen ) { + if ( getMaxVarcharLength() < maxLobLen ) { varcharBuilder.withTypeCapacity( maxLobLen, "text" ); } ddlTypeRegistry.addDescriptor( varcharBuilder.build() ); @@ -323,9 +323,9 @@ public class MySQLDialect extends Dialect { "char", this ) - .withTypeCapacity( getVarcharDdlTypeCapacity(), "varchar($l)" ) + .withTypeCapacity( getMaxVarcharLength(), "varchar($l)" ) .withTypeCapacity( maxMediumLobLen, "mediumtext" ); - if ( getVarcharDdlTypeCapacity() < maxLobLen ) { + if ( getMaxVarcharLength() < maxLobLen ) { nvarcharBuilder.withTypeCapacity( maxLobLen, "text" ); } ddlTypeRegistry.addDescriptor( nvarcharBuilder.build() ); @@ -336,9 +336,9 @@ public class MySQLDialect extends Dialect { "binary", this ) - .withTypeCapacity( getVarbinaryDdlTypeCapacity(), "varbinary($l)" ) + .withTypeCapacity( getMaxVarbinaryLength(), "varbinary($l)" ) .withTypeCapacity( maxMediumLobLen, "mediumblob" ); - if ( getVarbinaryDdlTypeCapacity() < maxLobLen ) { + if ( getMaxVarbinaryLength() < maxLobLen ) { varbinaryBuilder.withTypeCapacity( maxLobLen, "blob" ); } ddlTypeRegistry.addDescriptor( varbinaryBuilder.build() ); @@ -431,11 +431,13 @@ public class MySQLDialect extends Dialect { } } - public int getVarcharDdlTypeCapacity() { + @Override + public int getMaxVarcharLength() { return maxVarcharLength; } - public int getVarbinaryDdlTypeCapacity() { + @Override + public int getMaxVarbinaryLength() { return maxVarbinaryLength; } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/OracleArrayJdbcType.java b/hibernate-core/src/main/java/org/hibernate/dialect/OracleArrayJdbcType.java index 39a10e1da8..8f90de9e49 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/OracleArrayJdbcType.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/OracleArrayJdbcType.java @@ -96,7 +96,7 @@ public class OracleArrayJdbcType extends ArrayJdbcType { if ( typeName == null || typeName.isBlank() ) { typeName = dialect.getArrayTypeName( typeConfiguration.getDdlTypeRegistry().getTypeName( - elementType.getDefaultSqlTypeCode(), + elementType.getDdlTypeCode(), dialect ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/OracleSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/OracleSqlAstTranslator.java index d19aa5366d..3dcb53d0f3 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/OracleSqlAstTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/OracleSqlAstTranslator.java @@ -379,7 +379,7 @@ public class OracleSqlAstTranslator extends AbstractSql renderComparisonEmulateDecode( lhs, operator, rhs ); return; } - switch ( lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getJdbcTypeCode() ) { + switch ( lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() ) { case SqlTypes.SQLXML: // In Oracle, XMLTYPE is not "comparable", so we have to use the xmldiff function for this purpose switch ( operator ) { @@ -401,8 +401,11 @@ public class OracleSqlAstTranslator extends AbstractSql rhs.accept( this ); appendSql( "),'/*[local-name()=''xdiff'']/*')" ); break; + case SqlTypes.CLOB: + case SqlTypes.NCLOB: case SqlTypes.BLOB: - // In Oracle, BLOB types are not "comparable", so we have to use the dbms_lob.compare function for this purpose + // In Oracle, BLOB, CLOB and NCLOB types are not "comparable", + // so we have to use the dbms_lob.compare function for this purpose switch ( operator ) { case EQUAL: appendSql( "0=" ); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLSqlAstTranslator.java index 5bd7c3d095..a3bca46e51 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLSqlAstTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLSqlAstTranslator.java @@ -7,9 +7,9 @@ package org.hibernate.dialect; import org.hibernate.metamodel.mapping.JdbcMappingContainer; +import org.hibernate.query.sqm.ComparisonOperator; import org.hibernate.query.sqm.FetchClauseType; import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.query.sqm.FetchClauseType; import org.hibernate.sql.ast.spi.AbstractSqlAstTranslator; import org.hibernate.sql.ast.tree.Statement; import org.hibernate.sql.ast.tree.cte.CteMaterialization; @@ -26,6 +26,7 @@ import org.hibernate.sql.ast.tree.select.QueryPart; import org.hibernate.sql.ast.tree.select.QuerySpec; import org.hibernate.sql.exec.spi.JdbcOperation; import org.hibernate.sql.model.internal.TableInsertStandard; +import org.hibernate.type.SqlTypes; /** * A SQL AST translator for PostgreSQL. @@ -50,6 +51,33 @@ public class PostgreSQLSqlAstTranslator extends Abstrac expression.accept( this ); } + @Override + protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) { + final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType(); + if ( lhsExpressionType != null + && lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) { + // In PostgreSQL, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose + switch ( operator ) { + case EQUAL: + case NOT_DISTINCT_FROM: + case NOT_EQUAL: + case DISTINCT_FROM: + appendSql( "cast(" ); + lhs.accept( this ); + appendSql( " as text)" ); + appendSql( operator.sqlText() ); + appendSql( "cast(" ); + rhs.accept( this ); + appendSql( " as text)" ); + return; + default: + // Fall through + break; + } + } + renderComparisonStandard( lhs, operator, rhs ); + } + @Override public void visitBooleanExpressionPredicate(BooleanExpressionPredicate booleanExpressionPredicate) { final boolean isNegated = booleanExpressionPredicate.isNegated(); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerSqlAstTranslator.java index 1e2c424e04..ec567e76ed 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerSqlAstTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerSqlAstTranslator.java @@ -11,6 +11,7 @@ import java.util.List; import org.hibernate.LockMode; import org.hibernate.LockOptions; import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.metamodel.mapping.JdbcMappingContainer; import org.hibernate.query.sqm.ComparisonOperator; import org.hibernate.query.sqm.FetchClauseType; import org.hibernate.sql.ast.Clause; @@ -35,6 +36,7 @@ import org.hibernate.sql.ast.tree.select.QuerySpec; import org.hibernate.sql.ast.tree.select.SelectClause; import org.hibernate.sql.ast.tree.select.SortSpecification; import org.hibernate.sql.exec.spi.JdbcOperation; +import org.hibernate.type.SqlTypes; /** * A SQL AST translator for SQL Server. @@ -369,6 +371,28 @@ public class SQLServerSqlAstTranslator extends Abstract @Override protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) { + final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType(); + if ( lhsExpressionType != null + && lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) { + // In SQL Server, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose + switch ( operator ) { + case EQUAL: + case NOT_DISTINCT_FROM: + case NOT_EQUAL: + case DISTINCT_FROM: + appendSql( "cast(" ); + lhs.accept( this ); + appendSql( " as nvarchar(max))" ); + appendSql( operator.sqlText() ); + appendSql( "cast(" ); + rhs.accept( this ); + appendSql( " as nvarchar(max))" ); + return; + default: + // Fall through + break; + } + } renderComparisonEmulateIntersect( lhs, operator, rhs ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASEDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASEDialect.java index a88e875fa1..cb3ce3dfdf 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASEDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASEDialect.java @@ -66,7 +66,7 @@ public class SybaseASEDialect extends SybaseDialect { Integer precision, Integer scale, Long length) { - switch ( jdbcType.getDefaultSqlTypeCode() ) { + switch ( jdbcType.getDdlTypeCode() ) { case Types.FLOAT: // Sybase ASE allows FLOAT with a precision up to 48 if ( precision != null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/ConcatPipeFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/ConcatPipeFunction.java index e10a913db0..0f6d1a9660 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/ConcatPipeFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/ConcatPipeFunction.java @@ -54,7 +54,7 @@ public class ConcatPipeFunction extends AbstractSqmSelfRenderingFunctionDescript final Expression expression = (Expression) sqlAstArguments.get( i ); final JdbcType jdbcType = expression.getExpressionType().getJdbcMappings().get( 0 ).getJdbcType(); sqlAppender.appendSql( separator ); - switch ( jdbcType.getJdbcTypeCode() ) { + switch ( jdbcType.getDdlTypeCode() ) { case SqlTypes.CLOB: case SqlTypes.NCLOB: clobPatternRenderer.render( sqlAppender, Collections.singletonList( expression ), walker ); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/LengthFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/LengthFunction.java index f35806c078..793a880799 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/LengthFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/LengthFunction.java @@ -57,7 +57,7 @@ public class LengthFunction extends AbstractSqmSelfRenderingFunctionDescriptor { SqlAstTranslator walker) { final Expression expression = (Expression) sqlAstArguments.get( 0 ); final JdbcType jdbcType = expression.getExpressionType().getJdbcMappings().get( 0 ).getJdbcType(); - switch ( jdbcType.getJdbcTypeCode() ) { + switch ( jdbcType.getDdlTypeCode() ) { case SqlTypes.CLOB: case SqlTypes.NCLOB: clobPatternRenderer.render( sqlAppender, sqlAstArguments, walker ); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/SumReturnTypeResolver.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/SumReturnTypeResolver.java index aced63b13b..fe93274ab8 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/SumReturnTypeResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/SumReturnTypeResolver.java @@ -73,7 +73,7 @@ class SumReturnTypeResolver implements FunctionReturnTypeResolver { return impliedType; } } - switch ( basicType.getJdbcType().getJdbcTypeCode() ) { + switch ( basicType.getJdbcType().getDefaultSqlTypeCode() ) { case Types.SMALLINT: case Types.TINYINT: case Types.INTEGER: @@ -102,7 +102,7 @@ class SumReturnTypeResolver implements FunctionReturnTypeResolver { } // Resolve according to JPA spec 4.8.5 final BasicValuedMapping specifiedArgType = extractArgumentValuedMapping( arguments, 1 ); - switch ( specifiedArgType.getJdbcMapping().getJdbcType().getJdbcTypeCode() ) { + switch ( specifiedArgType.getJdbcMapping().getJdbcType().getDefaultSqlTypeCode() ) { case Types.SMALLINT: case Types.TINYINT: case Types.INTEGER: diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/temptable/StandardTemporaryTableExporter.java b/hibernate-core/src/main/java/org/hibernate/dialect/temptable/StandardTemporaryTableExporter.java index 54b520c2ed..35fa978da5 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/temptable/StandardTemporaryTableExporter.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/temptable/StandardTemporaryTableExporter.java @@ -45,7 +45,7 @@ public class StandardTemporaryTableExporter implements TemporaryTableExporter { for ( TemporaryTableColumn column : temporaryTable.getColumnsForExport() ) { buffer.append( column.getColumnName() ).append( ' ' ); - final int sqlTypeCode = column.getJdbcMapping().getJdbcType().getDefaultSqlTypeCode(); + final int sqlTypeCode = column.getJdbcMapping().getJdbcType().getDdlTypeCode(); final String databaseTypeName = column.getSqlTypeDefinition(); buffer.append( databaseTypeName ); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/temptable/TemporaryTable.java b/hibernate-core/src/main/java/org/hibernate/dialect/temptable/TemporaryTable.java index 0042580f74..a4c405d8de 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/temptable/TemporaryTable.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/temptable/TemporaryTable.java @@ -135,7 +135,7 @@ public class TemporaryTable implements Exportable, Contributable { this, uuidType, typeConfiguration.getDdlTypeRegistry().getTypeName( - uuidType.getJdbcType().getDefaultSqlTypeCode(), + uuidType.getJdbcType().getDdlTypeCode(), size ), size @@ -406,7 +406,7 @@ public class TemporaryTable implements Exportable, Contributable { final String rowNumberType; if ( dialect.supportsWindowFunctions() ) { rowNumberType = typeConfiguration.getDdlTypeRegistry().getTypeName( - integerBasicType.getJdbcType().getJdbcTypeCode(), + integerBasicType.getJdbcType().getDdlTypeCode(), dialect.getSizeStrategy().resolveSize( integerBasicType.getJdbcType(), integerBasicType.getJavaTypeDescriptor(), @@ -418,7 +418,7 @@ public class TemporaryTable implements Exportable, Contributable { } else if ( dialect.getIdentityColumnSupport().supportsIdentityColumns() ) { rowNumberType = typeConfiguration.getDdlTypeRegistry().getTypeName( - integerBasicType.getJdbcType().getJdbcTypeCode(), + integerBasicType.getJdbcType().getDdlTypeCode(), dialect.getSizeStrategy().resolveSize( integerBasicType.getJdbcType(), integerBasicType.getJavaTypeDescriptor(), @@ -426,13 +426,13 @@ public class TemporaryTable implements Exportable, Contributable { null, null ) - ) + " " + - dialect.getIdentityColumnSupport().getIdentityColumnString( integerBasicType.getJdbcType().getJdbcTypeCode() ); + ) + " " + dialect.getIdentityColumnSupport() + .getIdentityColumnString( integerBasicType.getJdbcType().getDdlTypeCode() ); } else { LOG.multiTableInsertNotAvailable( entityBinding.getEntityName() ); rowNumberType = typeConfiguration.getDdlTypeRegistry().getTypeName( - integerBasicType.getJdbcType().getJdbcTypeCode(), + integerBasicType.getJdbcType().getDdlTypeCode(), dialect.getSizeStrategy().resolveSize( integerBasicType.getJdbcType(), integerBasicType.getJavaTypeDescriptor(), diff --git a/hibernate-core/src/main/java/org/hibernate/id/ExportableColumn.java b/hibernate-core/src/main/java/org/hibernate/id/ExportableColumn.java index 6248cb1888..05f943051d 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/ExportableColumn.java +++ b/hibernate-core/src/main/java/org/hibernate/id/ExportableColumn.java @@ -13,6 +13,7 @@ import java.util.NoSuchElementException; import org.hibernate.FetchMode; import org.hibernate.MappingException; import org.hibernate.boot.model.relational.Database; +import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.engine.spi.Mapping; import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.mapping.Column; @@ -37,7 +38,7 @@ public class ExportableColumn extends Column { type, database.getTypeConfiguration() .getDdlTypeRegistry() - .getTypeName( type.getJdbcType().getDefaultSqlTypeCode(), database.getDialect() ) + .getTypeName( type.getJdbcType().getDdlTypeCode(), database.getDialect() ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java b/hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java index 55a0ee39fd..5615322efe 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java @@ -330,7 +330,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol private void resolveColumn(Column column, Dialect dialect) { if ( column.getSqlTypeCode() == null ) { - column.setSqlTypeCode( resolution.getJdbcType().getDefaultSqlTypeCode() ); + column.setSqlTypeCode( resolution.getJdbcType().getDdlTypeCode() ); } if ( resolution.getValueConverter() != null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Column.java b/hibernate-core/src/main/java/org/hibernate/mapping/Column.java index bd7d22ce6a..e60752d95c 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Column.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Column.java @@ -241,7 +241,7 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn final BasicType elementType = containerType.getElementType(); final int sqlTypeCode; try { - sqlTypeCode = elementType.getJdbcType().getDefaultSqlTypeCode(); + sqlTypeCode = elementType.getJdbcType().getDdlTypeCode(); } catch (Exception e) { throw new MappingException( diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java b/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java index bf945dbe6a..9b72d7ec6b 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java @@ -724,7 +724,7 @@ public abstract class SimpleValue implements KeyValue { } } ); - int jdbcTypeCode = recommendedJdbcType.getDefaultSqlTypeCode(); + int jdbcTypeCode = recommendedJdbcType.getDdlTypeCode(); if ( isLob() ) { if ( LobTypeMappings.isMappedToKnownLobCode( jdbcTypeCode ) ) { jdbcTypeCode = LobTypeMappings.getLobCodeTypeMapping( jdbcTypeCode ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/convert/internal/NamedEnumValueConverter.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/convert/internal/NamedEnumValueConverter.java index afe14e0bdf..1de3d14e8d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/convert/internal/NamedEnumValueConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/convert/internal/NamedEnumValueConverter.java @@ -60,10 +60,6 @@ public class NamedEnumValueConverter> implements EnumValueConv @Override public int getJdbcTypeCode() { - return jdbcType.getJdbcTypeCode(); - } - - public int getDefaultSqlTypeCode() { return jdbcType.getDefaultSqlTypeCode(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/convert/internal/OrdinalEnumValueConverter.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/convert/internal/OrdinalEnumValueConverter.java index e9bc2b05aa..3ee04d3372 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/convert/internal/OrdinalEnumValueConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/convert/internal/OrdinalEnumValueConverter.java @@ -50,7 +50,7 @@ public class OrdinalEnumValueConverter, N extends Number> impl @Override public int getJdbcTypeCode() { - return jdbcType.getJdbcTypeCode(); + return jdbcType.getDefaultSqlTypeCode(); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index b0c2435687..c533a69876 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -2742,7 +2742,7 @@ public abstract class AbstractEntityPersister .getIdentitySelectString( getTableName( 0 ), getKeyColumns( 0 )[0], - ( (BasicType) getIdentifierType() ).getJdbcType().getDefaultSqlTypeCode() + ( (BasicType) getIdentifierType() ).getJdbcType().getDdlTypeCode() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java index 1722b06c68..b34e2fcf9e 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java @@ -591,7 +591,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { // If there is no selectable mapping for a table name, we render a null expression selectableMapping = selectableMappings.values().iterator().next(); final int sqlType = selectableMapping.getJdbcMapping().getJdbcType() - .getDefaultSqlTypeCode(); + .getDdlTypeCode(); buf.append( dialect.getSelectClauseNullString( sqlType, getFactory().getTypeConfiguration() ) ) .append( " as " ); } diff --git a/hibernate-core/src/main/java/org/hibernate/procedure/internal/FunctionReturnImpl.java b/hibernate-core/src/main/java/org/hibernate/procedure/internal/FunctionReturnImpl.java index 4d1c33df6b..7372f76b49 100644 --- a/hibernate-core/src/main/java/org/hibernate/procedure/internal/FunctionReturnImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/procedure/internal/FunctionReturnImpl.java @@ -33,18 +33,18 @@ import jakarta.persistence.ParameterMode; */ public class FunctionReturnImpl implements FunctionReturnImplementor { private final ProcedureCallImplementor procedureCall; - private final int jdbcTypeCode; + private final int sqlTypeCode; private OutputableType ormType; - public FunctionReturnImpl(ProcedureCallImplementor procedureCall, int jdbcTypeCode) { + public FunctionReturnImpl(ProcedureCallImplementor procedureCall, int sqlTypeCode) { this.procedureCall = procedureCall; - this.jdbcTypeCode = jdbcTypeCode; + this.sqlTypeCode = sqlTypeCode; } public FunctionReturnImpl(ProcedureCallImplementor procedureCall, OutputableType ormType) { this.procedureCall = procedureCall; - this.jdbcTypeCode = ormType.getJdbcType().getJdbcTypeCode(); + this.sqlTypeCode = ormType.getJdbcType().getDefaultSqlTypeCode(); this.ormType = ormType; } @@ -85,7 +85,7 @@ public class FunctionReturnImpl implements FunctionReturnImplementor { @Override public int getJdbcTypeCode() { - return jdbcTypeCode; + return sqlTypeCode; } @Override @@ -137,7 +137,7 @@ public class FunctionReturnImpl implements FunctionReturnImplementor { return new FunctionReturnImpl<>( procedureCall, ormType ); } else { - return new FunctionReturnImpl<>( procedureCall, jdbcTypeCode ); + return new FunctionReturnImpl<>( procedureCall, sqlTypeCode ); } }; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java index a2989d5f3b..dd2f7bd365 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java @@ -320,7 +320,7 @@ public abstract class AbstractSelectionQuery } } if ( jdbcType != null ) { - switch ( jdbcType.getJdbcTypeCode() ) { + switch ( jdbcType.getDefaultSqlTypeCode() ) { case Types.DATE: if ( resultClass.isAssignableFrom( java.sql.Date.class ) ) { return; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/StandardFunctionReturnTypeResolvers.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/StandardFunctionReturnTypeResolvers.java index 090e2c83db..bbb33e19df 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/StandardFunctionReturnTypeResolvers.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/StandardFunctionReturnTypeResolvers.java @@ -140,8 +140,8 @@ public class StandardFunctionReturnTypeResolvers { //that is determined by how the function is used in the HQL query. In essence //the types are compatible if the map to the same JDBC type, of if they are //both numeric types. - int impliedTypeCode = ((BasicType) implied).getJdbcMapping().getJdbcType().getJdbcTypeCode(); - int definedTypeCode = ((BasicType) defined).getJdbcMapping().getJdbcType().getJdbcTypeCode(); + int impliedTypeCode = ((BasicType) implied).getJdbcMapping().getJdbcType().getDefaultSqlTypeCode(); + int definedTypeCode = ((BasicType) defined).getJdbcMapping().getJdbcType().getDefaultSqlTypeCode(); return impliedTypeCode == definedTypeCode || isNumeric( impliedTypeCode ) && isNumeric( definedTypeCode ); } @@ -181,8 +181,8 @@ public class StandardFunctionReturnTypeResolvers { //that is determined by how the function is used in the HQL query. In essence //the types are compatible if the map to the same JDBC type, of if they are //both numeric types. - int impliedTypeCode = implied.getJdbcMapping().getJdbcType().getJdbcTypeCode(); - int definedTypeCode = defined.getJdbcMapping().getJdbcType().getJdbcTypeCode(); + int impliedTypeCode = implied.getJdbcMapping().getJdbcType().getDefaultSqlTypeCode(); + int definedTypeCode = defined.getJdbcMapping().getJdbcType().getDefaultSqlTypeCode(); return impliedTypeCode == definedTypeCode || isNumeric( impliedTypeCode ) && isNumeric( definedTypeCode ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java index 26d8a79c5e..b3ecff4b09 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java @@ -5525,7 +5525,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base else { SqlTypedMapping sqlTypedMapping = null; if ( bindable instanceof BasicType ) { - final int sqlTypeCode = ( (BasicType) bindable ).getJdbcType().getDefaultSqlTypeCode(); + final int sqlTypeCode = ( (BasicType) bindable ).getJdbcType().getDdlTypeCode(); if ( sqlTypeCode == SqlTypes.NUMERIC || sqlTypeCode == SqlTypes.DECIMAL ) { // For numeric and decimal parameter types we must determine the precision/scale of the value. // When we need to cast the parameter later, it is necessary to know the size to avoid truncation. diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java index a9b6f3626f..2d6ec2432b 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java @@ -6120,7 +6120,7 @@ public abstract class AbstractSqlAstTranslator implemen final BasicPluralType containerType = (BasicPluralType) expressionType; final BasicType elementType = containerType.getElementType(); final String elementTypeName = sessionFactory.getTypeConfiguration().getDdlTypeRegistry() - .getDescriptor( elementType.getJdbcType().getDefaultSqlTypeCode() ) + .getDescriptor( elementType.getJdbcType().getDdlTypeCode() ) .getCastTypeName( elementType, castTarget.getLength(), @@ -6135,7 +6135,7 @@ public abstract class AbstractSqlAstTranslator implemen } final DdlTypeRegistry ddlTypeRegistry = getSessionFactory().getTypeConfiguration().getDdlTypeRegistry(); DdlType ddlType = ddlTypeRegistry - .getDescriptor( expressionType.getJdbcMapping().getJdbcType().getDefaultSqlTypeCode() ); + .getDescriptor( expressionType.getJdbcMapping().getJdbcType().getDdlTypeCode() ); if ( ddlType == null ) { // this may happen when selecting a null value like `SELECT null from ...` // some dbs need the value to be cast so not knowing the real type we fall back to INTEGER diff --git a/hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java b/hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java index 6d780df854..48ccc74dd0 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java @@ -50,7 +50,7 @@ public abstract class AbstractStandardBasicType public AbstractStandardBasicType(JdbcType jdbcType, JavaType javaType) { this.jdbcType = jdbcType; - this.sqlTypes = new int[] { jdbcType.getDefaultSqlTypeCode() }; + this.sqlTypes = new int[] { jdbcType.getDdlTypeCode() }; this.javaType = javaType; this.jdbcValueBinder = jdbcType.getBinder( javaType ); @@ -347,7 +347,7 @@ public abstract class AbstractStandardBasicType // and the cast type determination here. Note that we interpret the converter in ConvertedBasicTypeImpl // to properly determine the correct cast type final JdbcType jdbcType = getJdbcType(); - final int jdbcTypeCode = jdbcType.getJdbcTypeCode(); + final int jdbcTypeCode = jdbcType.getDdlTypeCode(); switch ( jdbcTypeCode ) { case Types.BIT: case Types.SMALLINT: diff --git a/hibernate-core/src/main/java/org/hibernate/type/CustomType.java b/hibernate-core/src/main/java/org/hibernate/type/CustomType.java index 8801e4608c..b19fe2d859 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/CustomType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/CustomType.java @@ -140,7 +140,7 @@ public class CustomType @Override public int[] getSqlTypeCodes(Mapping pi) { - return new int[] { jdbcType.getDefaultSqlTypeCode() }; + return new int[] { jdbcType.getDdlTypeCode() }; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/SerializableToBlobType.java b/hibernate-core/src/main/java/org/hibernate/type/SerializableToBlobType.java index febcfcaa10..676b5b4f6f 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/SerializableToBlobType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/SerializableToBlobType.java @@ -60,7 +60,7 @@ public class SerializableToBlobType implements BasicType public SerializableToBlobType() { this.jdbcType = BlobJdbcType.DEFAULT; - this.sqlTypes = new int[] { jdbcType.getDefaultSqlTypeCode() }; + this.sqlTypes = new int[] { jdbcType.getDdlTypeCode() }; this.javaType = new SerializableJavaType( Serializable.class ); this.jdbcValueBinder = jdbcType.getBinder( javaType ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/StandardBasicTypeTemplate.java b/hibernate-core/src/main/java/org/hibernate/type/StandardBasicTypeTemplate.java index bf39a0ba5e..9dad11ae53 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/StandardBasicTypeTemplate.java +++ b/hibernate-core/src/main/java/org/hibernate/type/StandardBasicTypeTemplate.java @@ -29,7 +29,7 @@ public class StandardBasicTypeTemplate extends AbstractSingleColumnStandardBa this.registrationKeys = registrationKeys; this.name = javaType.getJavaType() == null ? "(map-mode)" : javaType.getJavaType().getTypeName() - + " -> " + jdbcType.getJdbcTypeCode(); + + " -> " + jdbcType.getDefaultSqlTypeCode(); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DurationJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DurationJavaType.java index 59443c67c9..299f5fa1c6 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DurationJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DurationJavaType.java @@ -142,7 +142,7 @@ public class DurationJavaType extends AbstractClassJavaType { @Override public int getDefaultSqlPrecision(Dialect dialect, JdbcType jdbcType) { - if ( jdbcType.getDefaultSqlTypeCode() == SqlTypes.INTERVAL_SECOND ) { + if ( jdbcType.getDdlTypeCode() == SqlTypes.INTERVAL_SECOND ) { // Usually the maximum precision for interval types return 18; } @@ -158,7 +158,7 @@ public class DurationJavaType extends AbstractClassJavaType { @Override public int getDefaultSqlScale(Dialect dialect, JdbcType jdbcType) { - if ( jdbcType.getDefaultSqlTypeCode() == SqlTypes.INTERVAL_SECOND ) { + if ( jdbcType.getDdlTypeCode() == SqlTypes.INTERVAL_SECOND ) { // The default scale necessary is 9 i.e. nanosecond resolution return 9; } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/ArrayJdbcType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/ArrayJdbcType.java index 2abb55719e..2bc67e9857 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/ArrayJdbcType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/ArrayJdbcType.java @@ -183,7 +183,7 @@ public class ArrayJdbcType implements JdbcType { .resolveSize( elementJdbcType, containerJavaType.getElementJavaType(), null, null, null ); String typeName = session.getTypeConfiguration() .getDdlTypeRegistry() - .getDescriptor( elementJdbcType.getDefaultSqlTypeCode() ) + .getDescriptor( elementJdbcType.getDdlTypeCode() ) .getTypeName( size ); int cutIndex = typeName.indexOf( '(' ); if ( cutIndex > 0 ) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/DoubleJdbcType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/DoubleJdbcType.java index 4d537e98b0..ffd5e93fe4 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/DoubleJdbcType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/DoubleJdbcType.java @@ -12,6 +12,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; +import org.hibernate.query.sqm.CastType; import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.ValueExtractor; import org.hibernate.type.descriptor.WrapperOptions; @@ -43,10 +44,15 @@ public class DoubleJdbcType implements JdbcType { * @return {@link Types#FLOAT} for schema generation */ @Override - public int getDefaultSqlTypeCode() { + public int getDdlTypeCode() { return Types.FLOAT; } + @Override + public CastType getCastType() { + return CastType.DOUBLE; + } + @Override public String getFriendlyName() { return "DOUBLE"; diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/JdbcType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/JdbcType.java index 44894a0632..31d931138a 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/JdbcType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/JdbcType.java @@ -70,6 +70,18 @@ public interface JdbcType extends Serializable { */ int getJdbcTypeCode(); + /** + * A {@linkplain SqlTypes JDBC type code} that identifies the SQL column type. + *

+ * This value might be different from {@link #getDdlTypeCode()} if the actual type + * e.g. JSON is emulated through a type like CLOB. + * + * @return a JDBC type code + */ + default int getDefaultSqlTypeCode() { + return getJdbcTypeCode(); + } + /** * A {@linkplain SqlTypes JDBC type code} that identifies the SQL column type to * be used for schema generation. @@ -78,9 +90,10 @@ public interface JdbcType extends Serializable { * to obtain the SQL column type. * * @return a JDBC type code + * @since 6.2 */ - default int getDefaultSqlTypeCode() { - return getJdbcTypeCode(); + default int getDdlTypeCode() { + return getDefaultSqlTypeCode(); } default JavaType getJdbcRecommendedJavaTypeMapping( @@ -148,37 +161,37 @@ public interface JdbcType extends Serializable { } default boolean isInteger() { - int typeCode = getJdbcTypeCode(); + int typeCode = getDdlTypeCode(); return SqlTypes.isIntegral(typeCode) || typeCode == Types.BIT; //HIGHLY DUBIOUS! } default boolean isFloat() { - return SqlTypes.isFloatOrRealOrDouble( getJdbcTypeCode() ); + return SqlTypes.isFloatOrRealOrDouble( getDdlTypeCode() ); } default boolean isDecimal() { - return SqlTypes.isNumericOrDecimal( getJdbcTypeCode() ); + return SqlTypes.isNumericOrDecimal( getDdlTypeCode() ); } default boolean isNumber() { - return SqlTypes.isNumericType( getJdbcTypeCode() ); + return SqlTypes.isNumericType( getDdlTypeCode() ); } default boolean isBinary() { - return SqlTypes.isBinaryType( getJdbcTypeCode() ); + return SqlTypes.isBinaryType( getDdlTypeCode() ); } default boolean isString() { - return SqlTypes.isCharacterOrClobType( getJdbcTypeCode() ); + return SqlTypes.isCharacterOrClobType( getDdlTypeCode() ); } default boolean isTemporal() { - return SqlTypes.isTemporalType( getDefaultSqlTypeCode() ); + return SqlTypes.isTemporalType( getDdlTypeCode() ); } default boolean isLob() { - return isLob( getJdbcTypeCode() ); + return isLob( getDdlTypeCode() ); } static boolean isLob(int jdbcTypeCode) { @@ -193,7 +206,7 @@ public interface JdbcType extends Serializable { } default boolean isNationalized() { - return isNationalized( getJdbcTypeCode() ); + return isNationalized( getDdlTypeCode() ); } static boolean isNationalized(int jdbcTypeCode) { @@ -210,11 +223,11 @@ public interface JdbcType extends Serializable { } default boolean isInterval() { - return SqlTypes.isIntervalType( getDefaultSqlTypeCode() ); + return SqlTypes.isIntervalType( getDdlTypeCode() ); } default CastType getCastType() { - return getCastType( getJdbcTypeCode() ); + return getCastType( getDdlTypeCode() ); } static CastType getCastType(int typeCode) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/internal/DdlTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/internal/DdlTypeImpl.java index 9e5a6e5005..d3c0c8476f 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/internal/DdlTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/internal/DdlTypeImpl.java @@ -97,7 +97,7 @@ public class DdlTypeImpl implements DdlType { Long length = null; Integer precision = null; Integer scale = null; - switch ( jdbcType.getDefaultSqlTypeCode() ) { + switch ( jdbcType.getDdlTypeCode() ) { case SqlTypes.VARCHAR: length = (long) dialect.getMaxVarcharLength(); break; diff --git a/hibernate-core/src/main/java/org/hibernate/type/internal/ConvertedBasicTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/type/internal/ConvertedBasicTypeImpl.java index 601b0eccb2..b63ab6c8dc 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/internal/ConvertedBasicTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/type/internal/ConvertedBasicTypeImpl.java @@ -87,7 +87,7 @@ public class ConvertedBasicTypeImpl implements ConvertedBasicType, this.description = description; this.converter = converter; this.jdbcType = jdbcType; - this.sqlTypes = new int[] { jdbcType.getDefaultSqlTypeCode() }; + this.sqlTypes = new int[] { jdbcType.getDdlTypeCode() }; this.jdbcValueBinder = (ValueBinder) jdbcType.getBinder( converter.getRelationalJavaType() ); this.jdbcValueExtractor = (ValueExtractor) jdbcType.getExtractor( converter.getRelationalJavaType() ); this.jdbcLiteralFormatter = (JdbcLiteralFormatter) jdbcType.getJdbcLiteralFormatter( converter.getRelationalJavaType() ); @@ -377,7 +377,7 @@ public class ConvertedBasicTypeImpl implements ConvertedBasicType, @Override public CastType getCastType() { final JdbcType jdbcType = getJdbcType(); - final int jdbcTypeCode = jdbcType.getJdbcTypeCode(); + final int jdbcTypeCode = jdbcType.getDefaultSqlTypeCode(); switch ( jdbcTypeCode ) { case Types.BIT: case Types.SMALLINT: diff --git a/hibernate-core/src/main/java/org/hibernate/usertype/BaseUserTypeSupport.java b/hibernate-core/src/main/java/org/hibernate/usertype/BaseUserTypeSupport.java index 990ad15f11..4bdf6ac3a1 100644 --- a/hibernate-core/src/main/java/org/hibernate/usertype/BaseUserTypeSupport.java +++ b/hibernate-core/src/main/java/org/hibernate/usertype/BaseUserTypeSupport.java @@ -63,7 +63,7 @@ public abstract class BaseUserTypeSupport implements UserType { @Override public int getSqlType() { ensureResolved(); - return jdbcType.getDefaultSqlTypeCode(); + return jdbcType.getDdlTypeCode(); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/usertype/StaticUserTypeSupport.java b/hibernate-core/src/main/java/org/hibernate/usertype/StaticUserTypeSupport.java index 0e1a361da0..38ef2c5078 100644 --- a/hibernate-core/src/main/java/org/hibernate/usertype/StaticUserTypeSupport.java +++ b/hibernate-core/src/main/java/org/hibernate/usertype/StaticUserTypeSupport.java @@ -96,7 +96,7 @@ public class StaticUserTypeSupport implements UserType { @Override public int getSqlType() { - return jdbcType.getDefaultSqlTypeCode(); + return jdbcType.getDdlTypeCode(); } @Override diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AbstractCollectionMetadataGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AbstractCollectionMetadataGenerator.java index 9b2f841e4f..9720b678a7 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AbstractCollectionMetadataGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AbstractCollectionMetadataGenerator.java @@ -543,8 +543,8 @@ public abstract class AbstractCollectionMetadataGenerator extends AbstractMetada if ( !type.isComponentType() && !type.isAssociationType() && type instanceof BasicType ) { final BasicType basicType = (BasicType) type; return basicType.getJavaType() == String.class && ( - basicType.getJdbcType().getJdbcTypeCode() == Types.CLOB - || basicType.getJdbcType().getJdbcTypeCode() == Types.NCLOB + basicType.getJdbcType().getDdlTypeCode() == Types.CLOB + || basicType.getJdbcType().getDdlTypeCode() == Types.NCLOB ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/strategy/internal/ValidityAuditStrategy.java b/hibernate-envers/src/main/java/org/hibernate/envers/strategy/internal/ValidityAuditStrategy.java index 402428b878..4d2d763975 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/strategy/internal/ValidityAuditStrategy.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/strategy/internal/ValidityAuditStrategy.java @@ -451,8 +451,8 @@ public class ValidityAuditStrategy implements AuditStrategy { if ( collectionElementType instanceof BasicType ) { final BasicType basicType = (BasicType) collectionElementType; return basicType.getJavaType() == String.class && ( - basicType.getJdbcType().getJdbcTypeCode() == Types.CLOB - || basicType.getJdbcType().getJdbcTypeCode() == Types.NCLOB + basicType.getJdbcType().getDdlTypeCode() == Types.CLOB + || basicType.getJdbcType().getDdlTypeCode() == Types.NCLOB ); } return false;