title: How to use MySQL's full text search from JPA
body: <p>I want to use <a href="http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html" rel="noreferrer">MySQL's full text search</a> features using JPA, without having to use a native query. </p>
  
  <p>I am using EclipseLink, which has a function to support native SQL commands: <a href="http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/Support_for_Native_Database_Functions" rel="noreferrer">FUNC</a>. However, the help examples only show this being use with simple MySQL functions. My best effort attempt to get it to work with MATCH &amp; AGAINST is as follows:</p>
  
  <pre><code>@PersistenceContext(name="test")
  EntityManager em;
  
  Query query = em.createQuery("SELECT person FROM People person WHERE FUNC('MATCH', person.name) FUNC('AGAINST', :searchTerm)");
  ...
  query.getResultList();
  </code></pre>
  
  <p>Which gives the following exception:</p>
  
  <pre><code>Caused by: NoViableAltException(32@[()* loopback of 822:9: (m= MULTIPLY right= arithmeticFactor | d= DIVIDE right= arithmeticFactor )*])
      at org.eclipse.persistence.internal.libraries.antlr.runtime.DFA.noViableAlt(DFA.java:159)
      at org.eclipse.persistence.internal.libraries.antlr.runtime.DFA.predict(DFA.java:116)
      at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.arithmeticTerm(JPQLParser.java:4557)
      ... 120 more
  </code></pre>
  
  <p>I am open to alternatives other that using the FUNC method. </p>
  
  <p>I am using EJB 3 and EclipseLink 2.3.1.</p>