我收到了异常
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: dayofweek near line 1, column 155
以下是查询表格的函数
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();
请帮帮我..
答案 0 :(得分:1)
您需要使用createSQLQuery
方法:
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();