I'm using Hibernate 4 with PostgreSQL 9. I want to filter rows with a custom postgres function which looks as follows:
SELECT * FROM customer WHERE name % ?
(I am using the trigram search, a postgres extension).
To use this function with session.CreateQuery(), I implemented my own SQLFunction and PostgreSQLDialect following this tutorial.
The function works and looks as follows:
session.createQuery("FROM Customer WHERE trgm_match(name, :name) = true");
Now to the difficult part:
I need to query the table using several search criteria and want to use Hibernate's Criteria. How I can I use this custom PostgreSQL function in criteria.add(Restrictions. ?? );
I think that add( Restrictions.sqlRestriction("name % ?", filter, ??) ); might be sufficient, but what should I pass as the third argument? (The column has type VARCHAR)
I often saw the usage of Hibernate.STRING which doesn't seem to exist in Hibernate 4.
Any help would be appreciated.