Skip to content

Commit c94752d

Browse files
committed
HHH-7725 - Make handling multi-table bulk HQL operations more pluggable
1 parent 3e3b439 commit c94752d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,23 @@ public String getCastTypeName(int code) {
312312
return getTypeName( code, Column.DEFAULT_LENGTH, Column.DEFAULT_PRECISION, Column.DEFAULT_SCALE );
313313
}
314314

315+
public String cast(String value, int jdbcTypeCode, int length, int precision, int scale) {
316+
if ( jdbcTypeCode == Types.CHAR ) {
317+
return "cast(" + value + " as char(" + length + "))";
318+
}
319+
else {
320+
return "cast(" + value + "as " + getTypeName( jdbcTypeCode, length, precision, scale ) + ")";
321+
}
322+
}
323+
324+
public String cast(String value, int jdbcTypeCode, int length) {
325+
return cast( value, jdbcTypeCode, length, Column.DEFAULT_PRECISION, Column.DEFAULT_SCALE );
326+
}
327+
328+
public String cast(String value, int jdbcTypeCode, int precision, int scale) {
329+
return cast( value, jdbcTypeCode, Column.DEFAULT_LENGTH, precision, scale );
330+
}
331+
315332
/**
316333
* Subclasses register a type name for the given type code and maximum
317334
* column length. <tt>$l</tt> in the type name with be replaced by the

hibernate-core/src/main/java/org/hibernate/hql/spi/PersistentTableBulkIdStrategy.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.sql.PreparedStatement;
2828
import java.sql.SQLException;
2929
import java.sql.Statement;
30+
import java.sql.Types;
3031
import java.util.ArrayList;
3132
import java.util.Iterator;
3233
import java.util.List;
@@ -212,7 +213,10 @@ public DeleteHandler buildDeleteHandler(SessionFactoryImplementor factory, HqlSq
212213
return new TableBasedDeleteHandlerImpl( factory, walker ) {
213214
@Override
214215
protected String extraIdSelectValues() {
215-
return "cast(? as char)";
216+
final Dialect dialect = factory().getDialect();
217+
return dialect.requiresCastingOfParametersInSelectClause()
218+
? dialect.cast( "?", Types.CHAR, 36 )
219+
: "?";
216220
}
217221

218222
@Override

0 commit comments

Comments
 (0)