User Defined Functions in Dialect

@beikov

I ended up switching paths a little and using your pattern function idea. I can give the gory details of why i switched if curious.

Documentation for the next person trying to solve user defined functions in Hibernate.

Here is my final class to register my two full text search functions:

public class PgFunctionContributor implements FunctionContributor {
	@Override
	public void contributeFunctions(FunctionContributions functionContributions) {
		BasicType<Boolean> resolveType = functionContributions.getTypeConfiguration().getBasicTypeRegistry().resolve(StandardBasicTypes.BOOLEAN);
		functionContributions.getFunctionRegistry().registerPattern("ects","to_tsvector(?1) @@ websearch_to_tsquery(?2)",resolveType);
		functionContributions.getFunctionRegistry().registerPattern("ecfts","?1 @@ websearch_to_tsquery(?2)",resolveType);
	}
}

To register the functions:
A text file with the fully qualified class names of all defined function contributors is required.
The filename is /META-INF/services/org.hibernate.boot.model.FunctionContributor

Tim

1 Like