We are Migrating from springboot 2 to 3 which includes hibernate 5 to 6 migration
public class ExtendSqlServer2012Dialect extends SqlServer2012Dialect{
public ExtendSqlServer2012Dialect(){
registerFunction("datediffhr", new SQLFunctionemplate(StandardBasicTypes.INTEGER,"datediff(hour,?1,?2)"));
registerFunction("dateaddhr", new SQLFunctionemplate(StandardBasicTypes.TIMESTAMP,"dateaddhr(hour,0,?1)"));
}
}
Dialect now has a method initializeFunctionRegistry. The direct equivalent would be:
public class ExtendSqlServer2012Dialect extends SqlServerDialect{
@Override
public void initializeFunctionRegistry(FunctionContributions functionContributions) {
super.initializeFunctionRegistry(functionContributions);
SqmFunctionRegistry registry = functionContributions.getFunctionRegistry();
TypeConfiguration types = functionContributions.getTypeConfiguration();
new PatternFunctionDescriptorBuilder(registry, "datediffhr", FunctionKind.NORMAL, "datediff(hour,?1,?2)")
.setExactArgumentCount(2)
.setInvariantType(types.getBasicTypeForJavaType(integer.class))
.register();
}
}
You may find registry.registerNamed easier to use, or you may like to use a different SqmFunctionDescriptor subclass.
You can also use an independent FunctionContributor registered via SPI instead of extending the Dialect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With