2015-04-20 60 views
1

我得到異常休眠QuerySyntaxException

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

這個「白天」的意思究竟是什麼,在「間隔」和「白天」之間不應該有一些標誌?出現錯誤時出現 – pezetem

回答

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(); 
+0

無法提取ResultSet – robin