Reputation: 1925
I am getting the exception
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: dayofweek near line 1, column 155
Below is my function to query the table
Session session = getSession();
Query query = session.createQuery("select count(tex.task.id)" + " from " + TestExecution.class.getName() + " tex where tex.userId=:userId and " +
"tex.executedAt >= curdate()- interval dayofweek(curdate())+6 day and tex.executedAt < curdate() - interval dayofweek(curdate())-1 DAY");
query.setParameter("userId", userId);
return (long) query.uniqueResult();
Please help me..
Upvotes: 1
Views: 1568
Reputation: 153780
You need to use the createSQLQuery
method instead:
Session session = getSession();
Query query = session.createSQLQuery("select count(tex.task.id)" + " from " + TestExecution.class.getName() + " tex where tex.userId=:userId and " +
"tex.executedAt >= curdate()- interval dayofweek(curdate())+6 day and tex.executedAt < curdate() - interval dayofweek(curdate())-1 DAY");
query.setParameter("userId", userId);
return (long) query.uniqueResult();
Upvotes: 1