0

我有 MYSQL 查询

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

但是我在休眠中找不到 WEEKDAY 函数有没有最好的方法来解决它

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

query=session.createSQLQuery("SELECT weekday(CreatedDate), count(CreatedDate) FROM bug_list GROUP BY WEEKDAY(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("");

        }
4

1 回答 1

4

WEEKDAY不是标准 SQL,因此如果您希望使用 Hibernate,则必须滚动自定义HibernateDialect,在其中执行以下操作...

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

如此处所见。

于 2012-08-08T13:48:35.930 回答