Aarkan Aarkan - 5 months ago 47
MySQL Question

Using mysql FULLTEXT search with hibernate

I have a table in MYSQL which uses FULLTEXT index on few columns. I am using hibernate to access MYSQL database in my web application. When I try to search on the FULLTEXT columns, using the following hibernate query:

From posts p where MATCH (p.description) AGAINST ('testing')


I am getting the following exception from hibernate:

antlr.NoViableAltException: unexpected token: AGAINST


It seems that hibernate (version 4.3.11) does not understand the MYSQL FULLTEXT search expressions. Is there a way I can use that with hibernate? Any suggestions are welcome. Thanks in advance.

Answer

You have the following options:

  1. Use native SQL
  2. Implement a custom database functions for AGAINST.See this and this for an example.