title: HQL doesn't allow REGEXP or RLIKE for MySQL with Hibernate 5
body: <p>I'm trying to add <strong>RLIKE</strong> condition to an <strong>HQL</strong> query but I'm getting "<strong>unexpected token: rlike</strong>" error message on HQL validation.</p>
  
  <p>I'm using Spring boot with Spring-data and Hibernate 5 over MySQL.</p>
  
  <p>Query:
  </p>
  
  <pre><code>@Query("from PortEntity p where  p.name rlike '(gigabit)-(\\d)\\/(\\d)' ")
  @EntityGraph(attributePaths = {"parentSlot", "parentSlot.device"})
  List&lt;PortEntity&gt; findGigabitDevices(Pageable pageable);
  </code></pre>
  
  <p>And the error log:
  </p>
  
  <pre><code>01:26:21.033 16751 [restartedMain] DEBUG o.h.hql.internal.ast.ErrorCounter incident: - throwQueryException() : no errors 
  01:26:21.035 16753 [restartedMain] DEBUG o.h.h.i.ast.QueryTranslatorImpl incident: - parse() - HQL: from com.***.***.entity.PortEntity p where p.name rlike '(gigabit)-(\d)\/(\d)'  
  01:26:21.037 16755 [restartedMain] ERROR o.h.hql.internal.ast.ErrorCounter incident: - line 1:75: unexpected token: rlike 
  01:26:21.043 16761 [restartedMain] ERROR o.h.hql.internal.ast.ErrorCounter incident: - line 1:75: unexpected token: rlike 
  antlr.NoViableAltException: unexpected token: rlike
          at org.hibernate.hql.internal.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:784)
          at org.hibernate.hql.internal.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:316)
          at org.hibernate.hql.internal.antlr.HqlBaseParser.statement(HqlBaseParser.java:198)
          at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:283)
          at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:186)
          at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:141)
          at org.hibernate.engine.query.spi.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:115)
          at org.hibernate.engine.query.spi.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:77)
          at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:153)
          at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:546)
          at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:655)
          at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:23)
          at sun.reflect.GeneratedMethodAccessor64.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:498)
          at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:347)
          at com.sun.proxy.$Proxy152.createQuery(Unknown Source)
          at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:86)
          at org.springframework.data.jpa.repository.query.SimpleJpaQuery.&lt;init&gt;(SimpleJpaQuery.java:62)
          at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromMethodWithQueryString(JpaQueryFactory.java:72)
          at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromQueryAnnotation(JpaQueryFactory.java:53)
          at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$DeclaredQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:144)
          at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:212)
          at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:77)
  </code></pre>
  
  <p>I've discovered that in new Hibernate versions, HQL is parsed via ANTLR-based parser, and it's grammar just doesn't have <strong>REGEX</strong> or <strong>RLIKE</strong> keywords:
  <a href="https://github.com/hibernate/hibernate-orm/blob/6ba328e7a03d2faaf648e85310e903f11211cbd8/hibernate-core/src/main/antlr/hql.g" rel="nofollow noreferrer">Hibernate HQL ANTLR grammar</a></p>
  
  <p>I've tried to switch to the classical HQL parser by adding Hibernate property</p>
  
  <pre><code>"hibernate.query.factory_class" = "org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory"
  </code></pre>
  
  <p>but in this case @EntityGraph stops working with message "EntityGraphs cannot be applied queries using the <strong>classic QueryTranslator</strong>":</p>
  
  <pre><code>01:56:59.412 91498 [http-nio-8080-exec-1] WARN  o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver incident:REQID3302215661531 - Resolved exception caused by Handler execution: org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.QueryException: EntityGraphs cannot be applied queries using the classic QueryTranslator!; nested exception is java.lang.IllegalArgumentException: org.hibernate.QueryException: EntityGraphs cannot be applied queries using the classic QueryTranslator!
  </code></pre>
  
  <p>Should something be configured to allow RLIKE / REGEXP usage in Hibernate 5 with ANTLR-based parser, or it's bug?</p>