Currently, when HQL contains "substring" function in HQL using DB2, Hibernate ends up rendering the function as "substr". If HQL contains string units (e.g., octets), as in: "select substring( e.description, 21, 11, octets ) from AnEntity e", Hibernate will throw an exception when the generated SQL (using "substr") is executed. If we simply change Hibernate to render "substring" instead of "substr", DB2 will throw an exception if string units is not provided. In other words, DB2 will throw an exception if an existing application using DB2 has HQL using "substring" function without string units, as in: "select substring( e.description, 21, 11 ) from AnEntity e". Since "substring" is defined in ANSI-92 without string units, I think Hibernate should support using "substring" with or without string units. My plan is to create a new StandardSQLFunction to deal with rendering the function name, depending on whether the last argument is one of the string units ("CODEUNITS16", "CODEUNITS32", "OCTETS"), regardless of case:
- if the last argument is a string unit, then "substring" will be the rendered function name;
- otherwise, "substr" will be the rendered function name.
When "substr" is used in HQL with DB2, Hibernate will continue to render the function name as "substr". |