We encountered a problem today where we wanted our queries to support the function CONTAINS for the HANA dialect with some appropriate mocking in an H2 dialect.
You can register custom functions, but the parser does not accept these as full expressions in a WHERE condition, meaning
SELECT … FROM … WHERE
CONTAINS(…),
which is the correct database syntax is not allowed by Hibernate, but
SELECT … FROM … WHERE
CONTAINS(…) = TRUE,
which is not correct for the database is allowed by Hibernate.
There appears to be a workaround for this where you render the function as “CONTAINS(…) AND TRUE” to make the second variant correct for the database.
Is better support for this type of custom function that is used as a full predicate planned?
There seem to be similar problems for CONTAINS and FREETEXT on SQL Server, so it is not just HANA.
I particularly don’t like that this encourages the HQL/JPQL queries to use a syntax that does not work anywhere and is only “fixed” in the renderer.
Best regards,
Richard
Related links:
https://docs.microsoft.com/en-us/sql/t-sql/queries/predicates?view=sql-server-2017
https://help.sap.com/viewer/4fe29514fd584807ac9f2a04f6754767/2.0.03/en-US/20f952437519101487edc3d9aba84238.html