Решение.
Регистрируем новую функцию в диалекте, у меня hibernate 6.3.1:
public class CustomPostgreSQL10Dialect extends PostgreSQLDialect {
@Override
public void initializeFunctionRegistry(FunctionContributions functionContributions) {
super.initializeFunctionRegistry(functionContributions);
SqmFunctionRegistry functionRegistry = functionContributions.getFunctionRegistry();
TypeConfiguration typeConfiguration = functionContributions.getTypeConfiguration();
BasicTypeRegistry basicTypeRegistry = typeConfiguration.getBasicTypeRegistry();
functionRegistry.patternDescriptorBuilder("@>", "(?1 @> ?2)")
.setExactArgumentCount(2)
.setParameterTypes(ANY, ANY)
.setInvariantType(basicTypeRegistry.resolve(StandardBasicTypes.BOOLEAN))
.register();
}
}
Меняем в конфигурациях диалект на свой:
spring.jpa.properties.hibernate.dialect = com.package.CustomPostgreSQL10Dialect
Дальше дописываем условие:
spec = Specification.where(spec).and((Specification<MyPoint>) (root, query, cb) -> {
Expression<Double> point1 = cb.function("ll_to_earth", Double.class,
root.get("latitude"), root.get("longitude"));
Expression<Double> point2 = cb.function("ll_to_earth", Double.class,
cb.literal("57.65"), cb.literal("38.38"));
Expression<?> earthBox = cb.function("earth_box", Object.class, point1, cb.literal(150d));
return cb.isTrue(cb.function("@>", Boolean.class, earthBox, point2));
});