gavin wrote:
It SHOULD be that the HQL parser will just pass through the MySQL full text search syntax. So try it.
But recently there was a report that it does not, in fact, let you do this. let me know.
Well, I may be doing something wrong, but it doesn't seem to be working for me. Here's what I did:
Code:
Query q = session.createQuery("FROM items WHERE MATCH (title) AGAINST (:query)");
q.setParameter("query", searchField.getText(), Hibernate.STRING);
This produces:
net.sf.hibernate.QueryException: Incorrect query syntax [FROM items WHERE MATCH (title) AGAINST (:query)]
So, passing the MySQL FULLTEXT query through doesnt seem to work.
I also downloaded the latest 2.1b4, and tried using createSQLQuery, ie:
Code:
Query q = session.createSQLQuery("SELECT {items.*} FROM items WHERE MATCH (title) AGAINST (:query)","items",Item.class);
q.setParameter("query", searchField.getText(), Hibernate.STRING);
This produces:
net.sf.hibernate.QueryException: Named parameter does not appear in Query: query [SELECT {items.*} FROM items WHERE MATCH (title) AGAINST (:query)]
Is this a parsing bug? I'm not sure about the rules re Hibernate parsing out named parameters - for example, this works fine:
Code:
Query q = session.createSQLQuery("SELECT {items.*} FROM items WHERE title LIKE :query","items",Item.class);
q.setParameter("query", searchField.getText(), Hibernate.STRING);
While this does not: (note the addition of the MySQL '%' wildcard to the ':query' parameter:
Code:
Query q = session.createSQLQuery("SELECT {items.*} FROM items WHERE title LIKE :query%","items",Item.class);
q.setParameter("query", searchField.getText(), Hibernate.STRING);
Above produces:
java.lang.IllegalArgumentException: Parameter query does not exist as a named parameter in [SELECT {items.*} FROM items WHERE title LIKE :query%]
So, there you go. It seems not to be working, but it could just be my relative newbiness.