【问题标题】:Hibernate QuerySyntaxException休眠查询语法异常
【发布时间】:2015-04-20 18:15:43
【问题描述】:

我遇到了异常

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

请帮帮我..

【问题讨论】:

  • 这个“dayofweek”到底是什么意思,“interval”和“dayofweek”之间不应该有什么符号吗?

标签: java mysql sql database hibernate


【解决方案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();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-08
    • 2021-08-01
    • 2012-03-29
    • 2014-03-09
    • 1970-01-01
    • 2013-12-24
    • 1970-01-01
    相关资源
    最近更新 更多