Hi,
I'm trying to support custom functions via HQL queries:
- ilike (because I would like to avoid the ugly lower() like lower()
- Postgresql full-text search ts_vector() @@ ts_query()
So I extended the PostgresqlDialect as explained in:
- https://forum.hibernate.org/viewtopic.php?p=2447426
- https://groups.google.com/forum/?fromgroups=#!topic/play-framework/UdmuM77yC24
(- http://stackoverflow.com/questions/11793159/how-to-use-oracles-regexp-like-in-hibernate-hql)
Code:
CustomPostgresDialect() {
super()
registerFunction( "custom_ilike", new VarArgsSQLFunction(StandardBasicTypes.BOOLEAN, "", " ilike ", ""));
}
Since I use hibernate with Grails, I added to Datasource.groovy:
Code:
dataSource {
dialect = "CustomPostgresDialect"
}
but when I run:
Code:
Item.executeQuery("SELECT DISTINCT i FROM Item i WHERE custom_ilike(i.status, '%')")
I got the following error:
Code:
org.springframework.orm.hibernate3.HibernateQueryException: unexpected AST node: ( near line 1, column 83 [SELECT DISTINCT i FROM com.auctelia.platform.model.sales.Item i WHERE custom_ilike(i.status, '%')]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: ( near line 1, column 83 [SELECT DISTINCT i FROM com.auctelia.platform.model.sales.Item i WHERE custom_ilike(i.status, '%')]
Did I miss something?
Any other preferred solutions? The only option I see would be raw SQL with new Sql(Datasource).
Thanks for your help!