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 c2dc83ef33..437c61845c 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java @@ -312,6 +312,23 @@ public abstract class Dialect implements ConversionContext { return getTypeName( code, Column.DEFAULT_LENGTH, Column.DEFAULT_PRECISION, Column.DEFAULT_SCALE ); } + public String cast(String value, int jdbcTypeCode, int length, int precision, int scale) { + if ( jdbcTypeCode == Types.CHAR ) { + return "cast(" + value + " as char(" + length + "))"; + } + else { + return "cast(" + value + "as " + getTypeName( jdbcTypeCode, length, precision, scale ) + ")"; + } + } + + public String cast(String value, int jdbcTypeCode, int length) { + return cast( value, jdbcTypeCode, length, Column.DEFAULT_PRECISION, Column.DEFAULT_SCALE ); + } + + public String cast(String value, int jdbcTypeCode, int precision, int scale) { + return cast( value, jdbcTypeCode, Column.DEFAULT_LENGTH, precision, scale ); + } + /** * Subclasses register a type name for the given type code and maximum * column length. $l in the type name with be replaced by the diff --git a/hibernate-core/src/main/java/org/hibernate/hql/spi/PersistentTableBulkIdStrategy.java b/hibernate-core/src/main/java/org/hibernate/hql/spi/PersistentTableBulkIdStrategy.java index 1655f13340..15cb17af46 100644 --- a/hibernate-core/src/main/java/org/hibernate/hql/spi/PersistentTableBulkIdStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/hql/spi/PersistentTableBulkIdStrategy.java @@ -27,6 +27,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Statement; +import java.sql.Types; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -212,7 +213,10 @@ public class PersistentTableBulkIdStrategy implements MultiTableBulkIdStrategy { return new TableBasedDeleteHandlerImpl( factory, walker ) { @Override protected String extraIdSelectValues() { - return "cast(? as char)"; + final Dialect dialect = factory().getDialect(); + return dialect.requiresCastingOfParametersInSelectClause() + ? dialect.cast( "?", Types.CHAR, 36 ) + : "?"; } @Override