【发布时间】:2016-09-15 14:39:41
【问题描述】:
以下 QueryDSL 代码有什么问题:
query.from(chat).where(
chat.datePosted.goe(startDate.atStartOfDay()).
and(chat.datePosted.lt(endDate.plusDays(1).atStartOfDay()))).
groupBy(date(chat.datePosted)).
list(date(chat.datePosted), date(chat.datePosted).count());
我得到这样的异常:
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: expecting CLOSE, found '(' near line 1, column 41 [select date(chat.datePosted), count(date(chat.datePosted))
from com.test.model.Chat chat
where chat.datePosted >= ?1 and chat.datePosted < ?2
group by date(chat.datePosted)]
?
我正在使用 Spring Boot 1.3.6 和 QueryDSL 3.7.4(JPA 通过 Hibernate)。
【问题讨论】:
-
似乎与 this question 有关,但我不相信 hibernate 无法解析如此简单的查询。
-
看起来问题出在 endDate.plusDays(1).atStartOfDay() 周围 - 也许先尝试计算然后传入值?
-
DATE 不是有效的 JPQL 函数。任何 JPQL 参考资料都会告诉您这一点
-
你可能是对的,但我也尝试过 queryDSL 本身支持的普通旧“concat”(或 StringExpression 附加),这也不起作用,所以根本原因是别的。
-
@JohnHarris 不,最终效果很好,请参阅答案。
标签: java hibernate jpa querydsl