# Custom Function without META-INF service entry?

**URL:** <https://discourse.hibernate.org/t/custom-function-without-meta-inf-service-entry/9258>\
**Category:** Hibernate ORM\
**Created:** [March 25, 2024, 11:49pm UTC](https://discourse.hibernate.org/t/custom-function-without-meta-inf-service-entry/9258 "2024-03-25T23:49:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![IVR\_Avenger](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/ivr_avenger/32/3091_2.png) [@IVR\_Avenger](https://discourse.hibernate.org/u/IVR_Avenger)\
**Post date:** [March 25, 2024, 11:49pm UTC](https://discourse.hibernate.org/t/custom-function-without-meta-inf-service-entry/9258/1 "2024-03-25T23:49:33Z")

</div>

Hello! I followed this excellent tutorial to migrate a custom function out of a Dialect and into a FunctionContributor:

> **[Hibernate 6 custom functions with Spring Data JPA repositories](https://aregall.tech/hibernate-6-custom-functions)**
>
> Hibernate 6 custom functions: how to register custom SQL functions using Hibernate 6 and calling them in Spring Data JPA repositories.

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!

---

<div class="post-metadata">

**Author:** ![mbladel](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbladel/32/2128_2.png) [@mbladel](https://discourse.hibernate.org/u/mbladel)\
**Post date:** [March 26, 2024, 1:00pm UTC](https://discourse.hibernate.org/t/custom-function-without-meta-inf-service-entry/9258/2 "2024-03-26T13:00:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ArnauAregall](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/arnauaregall/32/3184_2.png) [@ArnauAregall](https://discourse.hibernate.org/u/ArnauAregall)\
**Post date:** [May 4, 2024, 6:06am UTC](https://discourse.hibernate.org/t/custom-function-without-meta-inf-service-entry/9258/3 "2024-05-04T06:06:49Z")

</div>

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.
