Reputation: 2360
Can any one please help to escape from NOT(!) symbol in HQL. I am using Postgres 8.3. Also I am unable to search with these chars |\?'( )
fts('english',COLUMN_NAME,'" + searchText + "') = true)
Upvotes: 0
Views: 654
Reputation: 11735
You should be binding the search text instead of concatenating it manually to the query. Not only does it fixes your problem, it's also better in terms of security (SQL injection) and performance (the database sees the same query with different parameters, which allows it to cache the compiled query when it can).
Change your query so it looks like:
fts('english', COLUMN_NAME, :searchText) = true // using named parameters
// or
fts('english', COLUMN_NAME, ?) = true // using positional parameters
You can then properly bind your parameters:
session.createQuery(hqlQuery)
.setString("searchText", searchText)
.iterate();
// or
session.createQuery(hqlQuery)
.setString(0, searchText)
.iterate();
It's the same principle as using a PreparedStatement
with JDBC and setting the parameters (the main difference being that the parameters' indices start at 1 with JDBC and 0 with HQL).
Upvotes: 3