我有MYSQL查询

SELECT WEEKDAY(CreatedDate),
    COUNT(CreatedDate),
    CreatedDate FROM bug_List
GROUP BY
    WEEKDAY(CreatedDate)


但是我在休眠中找不到WEEKDAY函数,是否有任何最佳方法可以解决它

在这里我尝试从nativeSQL,但我得到了空数组对象

query = session.createSQLQuery(“ SELECT weekday(CreatedDate),
          从bug_list GROUP BY WEEKDAY(CreatedDate)开始计数(CreatedDate)“);

         result=query.list();

        Iterator resultIterator = result.iterator();
        while(resultIterator.hasNext())
        {
            Object[] obj = (Object[]) resultIterator.next();
            for (int i = 0; i < obj.length; i++) {
                System.out.print(obj[i] + "\t");
                }
            System.out.println("");

        }

最佳答案

WEEKDAY不是标准的SQL,因此,如果您想使用Hibernate,则必须运行一个自定义的HibernateDialect,在其中执行类似以下的操作...

registerFunction("weekday",
    new SQLFunctionTemplate(Hibernate.INTEGER, "to_char(?1,'D')"));


here所示。

10-06 06:12