Hello! I followed this excellent tutorial to migrate a custom function out of a Dialect and into a FunctionContributor:
This step is problematic, as our in-house pattern is to put all such kinds of configs into the application.yml:
The last step will be creating the Hibernate meta hint file in our classpath to instruct we want to register a custom FunctionContributor:
src/main/resources/META-INF/services/org.hibernate.boot.model.FunctionContributor
And on that file, add our custom function contributor full class name:
tech.aaregall.lab.hibernate6.persistence.functions.CustomFunctionsContributor
Can the reference to our CustomFunctionsContributor be expressed in the yaml somehow?
Thank you!
1 Like
As you can find in FunctionContributor
ās javadoc, there are programmatic alternatives to register custom implementations other than registering Java service:
org.hibernate.cfg.Configuration#registerFunctionContributor
org.hibernate.boot.MetadataBuilder#applyFunctions
You should always call one of these methods before constructing the SessionFactory
used in the application where you want your custom functions to be available.
Thanks for the kind words on my humble blog post!
Iām not sure if loading contributors dynamically from a YAML file is possible (I guess your intend is to apply Spring auto configuration fashion to Hibernate function contributors).
AFAIK @mbladel answer to me looks like the closest approach you could follow to dynamically register contributors - I have never tried it nor had the need though.