How to overwrite spatial function descriptors

Hi there,

I just created a bug report, as there are issues with spatial function descriptors for Oracle database: Jira

To solve this issue temporarily for me I tried to replace these with my own by using a FunctionContributor. But I realized that I cannot overwrite function descriptors with the FunctionContributor, but only add new ones.

So my question is this: Is it possible to overwrite function descriptors provided by hibernate with my own? And if so, how can I achieve this?

Kind regards,
Marko Skocibusic

Overriding functions should work just fine through FunctionContributor. We even added an optional ordinal to have ordering so that you can make sure your contributor runs after e.g. the spatial one.
What did you try so far? Did debugging reveal any issues?

Hi Christian. I overlooked the ordinal method in FunctionContributor and will give it a try.

When I debugged it yesterday, I saw that my FunctionContributor ran first and added my descriptors to an empty map. Afterwards Hibernate added its own descriptors through OracleSDOFunctionDescriptors used in OracleDialectContributor#contributeFunctions, overwriting mine. Reading the javadoc of FunctionContributor#ordinal it seems that the default behaviour should be different:

The range 0-500 is reserved for Hibernate, range 500-1000 for libraries and 1000-Integer.MAX_VALUE for user-defined FunctionContributors.

Contributions from higher precedence contributors (higher numbers) effectively override contributions from lower precedence. E.g. if a contributor with precedence 1000 contributes a function named “max”, that will override Hibernate’s standard function of that name.

Maybe using the MetadataBuilderContributor broke this mechanism, but I replaced it now with the Java Service Loader. See my other question: Register FunctionContributor programmatically

I will take a look into that later. Thank you for the hint, Christian!

Ok, later was right now. And yes, using MetadataBuilderContributor to register my FunctionContributor broke the ordinal mechanism.

Now, using the Java Service Loader to register my FunctionContributors solved my issue.

Thank you very much and kind regards,
Marko

Edit: So what did I learn? Never use deprecated code! :sweat_smile:

1 Like