hibernate执行hql语句问题!!

corruptsatan corruptsatan 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
String hql = "select new map(convert(char(10),a.testDate,111) as testDate,sum(totalCase) as totalCase,sum(okCase) as okCase,sum(pokCase) as pokCase,sum(ntCase) as ntCase,sum(ngCase) as ngCase) " +
"from AutoTestRecord as a " +
"where a.testDate between '"+DateUtil.formatDate(beginDate)+"' and '"+DateUtil.formatDate(endDate)+"' group by convert(char(10),a.testDate,111)";

执行时报错。
java.lang.NullPointerException
org.hibernate.hql.NameGenerator.generateColumnNames(NameGenerator.java:23)
org.hibernate.hql.ast.util.SessionFactoryHelper.generateColumnNames(SessionFactoryHelper.java:386)
org.hibernate.hql.ast.tree.SelectClause.initializeColumnNames(SelectClause.java:247)
org.hibernate.hql.ast.tree.SelectClause.finishInitialization(SelectClause.java:237)
org.hibernate.hql.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:231)
org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:704)
。。。
。。。

改成这样就可以:
String hql = "select new map('2010-06-17' as testDate,sum(totalCase) as totalCase,sum(okCase) as okCase,sum(pokCase) as pokCase,sum(ntCase) as ntCase,sum(ngCase) as ngCase) " +
"from AutoTestRecord as a " +
"where a.testDate between '"+DateUtil.formatDate(beginDate)+"' and '"+DateUtil.formatDate(endDate)+"' group by convert(char(10),a.testDate,111)";

因为testDate为datetime类型,而我只要group by 日期,所以必须转换,但convert函数在group by后面是可以,但前面我也要select出来用,但就是报错。
请高手指点!!
...全文
评论 4
收藏 已收藏
分享
返回顶部
corruptsatan
Web 开发 81,107 成员 341,720 内容