title: How to fix Named Query Error ( unexpected token: DAY ) in Hibernate?
body: <p>Following is my named query for finding activities older then 90 Days:</p>
  
  <pre><code>"DELETE FROM PAActivity pa WHERE pa.status IN (:statusSet) AND cast(pa.datoFinish as date) &lt; cast(DATE_SUB(current_date(), INTERVAL (:noofdays) DAY) as date)"
  </code></pre>
  
  <p>During compile time it gives following Hibernate exception:</p>
  
  <pre><code>ERROR 2018-04-24 11:00:07,579 o.h.h.i.a.ErrorCounter - line 1:243: unexpected token: DAY
  ERROR 2018-04-24 11:00:07,579 o.h.h.i.a.ErrorCounter - line 1:243: unexpected token: DAY
  line 1:243: unexpected token: DAY
      at org.hibernate.hql.internal.antlr.HqlBaseParser.primaryExpression(HqlBaseParser.java:876)
      at org.hibernate.hql.internal.antlr.HqlBaseParser.atom(HqlBaseParser.java:3472)
      at org.hibernate.hql.internal.antlr.HqlBaseParser.unaryExpression(HqlBaseParser.java:3250) .
  .
  .
  .
  .
  WARN  2018-04-24 11:00:07,641 o.h.h.i.a.HqlParser - HHH000203: processEqualityExpression() : No expression to process!
  ERROR 2018-04-24 11:00:08,094 o.h.i.SessionFactoryImpl - HHH000177: Error in named query: deletePAActivityByProcessIDs
  org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: DAY near line 1, column 243 [DELETE FROM fn.gover.model.PAActivity pa WHERE pa.status IN (:statusSet) AND cast(pa.datoFinish as date) &lt; cast(DATE_SUB(current_date(), INTERVAL (:noofdays) DAY) as date)]
      at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
      at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
  </code></pre>