Skip to content

Commit 2ccbef3

Browse files
committed
HHH-18803 Fix XML aggregate issues due to missing functions in DB2 10.5
1 parent d69d9c8 commit 2ccbef3

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/aggregate/DB2AggregateSupport.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public String aggregateComponentCustomReadExpression(
168168
case TIMESTAMP_UTC:
169169
return template.replace(
170170
placeholder,
171-
"cast(trim(trailing 'Z' from xmlcast(xmlquery(" + xmlExtractArguments( aggregateParentReadExpression, columnExpression ) + ") as varchar(35))) as " + column.getColumnDefinition() + ")"
171+
"cast(replace(trim(trailing 'Z' from xmlcast(xmlquery(" + xmlExtractArguments( aggregateParentReadExpression, columnExpression ) + ") as varchar(35))),'T',' ') as " + column.getColumnDefinition() + ")"
172172
);
173173
case SQLXML:
174174
return template.replace(
@@ -261,7 +261,8 @@ private static String xmlCustomWriteExpression(String customWriteExpression, Jdb
261261
// We encode binary data as hex
262262
return "hex(" + customWriteExpression + ")";
263263
case UUID:
264-
return "regexp_replace(lower(hex(" + customWriteExpression + ")),'^(.{8})(.{4})(.{4})(.{4})(.{12})$','$1-$2-$3-$4-$5')";
264+
// Old DB2 didn't support regexp_replace yet
265+
return "overlay(overlay(overlay(overlay(lower(hex(" + customWriteExpression + ")),'-',21,0,octets),'-',17,0,octets),'-',13,0,octets),'-',9,0,octets)";
265266
// case ARRAY:
266267
// case XML_ARRAY:
267268
// return "(" + customWriteExpression + ") format json";
@@ -754,7 +755,7 @@ private static boolean needsVarcharForBitDataCast(String columnType) {
754755
// xmlelement and xmltable don't seem to support the "varbinary", "binary" or "char for bit data" types
755756
final String columTypeLC = columnType.toLowerCase( Locale.ROOT ).trim();
756757
return columTypeLC.contains( "binary" )
757-
|| columTypeLC.startsWith( "char" ) && columTypeLC.endsWith( " bit data" );
758+
|| columTypeLC.contains( "char" ) && columTypeLC.endsWith( " bit data" );
758759
}
759760

760761
interface JsonWriteExpression {

0 commit comments

Comments
 (0)