Hello!
We recently migrated to Hibernate 6 from Hibernate 5 and that made us to change the code.
May I ask the community to check if I did the migration correctly? We used to use these lines of code:
public class DB2FunctionRegister extends DB2Dialect {
public DB2FunctionRegister() {
super();
registerFunction("listagg", new StandardSQLFunction("listagg"));
registerFunction("listaggDistinct",
new SQLFunctionTemplate(StandardBasicTypes.STRING, "LISTAGG(DISTINCT ?1,', ') "));
registerFunction("listaggDistinctLtrimZero",
new SQLFunctionTemplate(StandardBasicTypes.STRING, "LISTAGG(DISTINCT LTRIM(?1, '0'), ', ') "));
registerFunction("length", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "LENGTH(?1)"));
registerFunction("varcharFormat",
new StandardSQLFunction("varchar_format", StandardBasicTypes.STRING));
}
}
but as SQLFunctionTemplate
was removed in new Hibernate version I used this doc to upgrade the code to:
package com.company.config;
public class DB2FunctionRegister extends DB2Dialect implements FunctionContributor {
@Override
public void contributeFunctions(FunctionContributions functionContributions) {
functionContributions.getFunctionRegistry().register("string_agg",
new StandardSQLFunction("string_agg", StandardBasicTypes.STRING));
functionContributions.getFunctionRegistry().register("listagg",
new StandardSQLFunction("listagg", StandardBasicTypes.STRING));
functionContributions.getFunctionRegistry().registerPattern(
"listaggDistinct", "LISTAGG(DISTINCT ?1,', ') ",
functionContributions.getTypeConfiguration()
.getBasicTypeRegistry().resolve(StandardBasicTypes.STRING));
functionContributions.getFunctionRegistry().registerPattern(
"listaggDistinctLtrimZero", "LISTAGG(DISTINCT LTRIM(?1, '0'), ', ') ",
functionContributions.getTypeConfiguration()
.getBasicTypeRegistry().resolve(StandardBasicTypes.STRING));
functionContributions.getFunctionRegistry().registerPattern(
"length", "LENGTH(?1)",
functionContributions.getTypeConfiguration()
.getBasicTypeRegistry().resolve(StandardBasicTypes.INTEGER));
functionContributions.getFunctionRegistry().registerPattern(
"varcharFormat", "varchar_format",
functionContributions.getTypeConfiguration()
.getBasicTypeRegistry().resolve(StandardBasicTypes.STRING));
}
}
and also created META-INF/services/FunctionContributor
file and put com.company.config.DB2FunctionRegister
into it.
Have I made everything correct?
Thanks in advance,
Nick.