Mysql 将SQL查询转换为Hibernate查询
我需要帮助将一些sql转换为hibernate sql SQL: 我使用SQLQuery添加标量。我为HQL尝试了以下方法:Mysql 将SQL查询转换为Hibernate查询,mysql,sql,hibernate,hql,Mysql,Sql,Hibernate,Hql,我需要帮助将一些sql转换为hibernate sql SQL: 我使用SQLQuery添加标量。我为HQL尝试了以下方法: String hql = "select time, hour(time), minute(time) from db as O " + "where O.time >= :time group by 2 order by O.time"; Query query = session.createQuery(hql); query.setDa
String hql = "select time, hour(time), minute(time) from db as O "
+ "where O.time >= :time group by 2 order by O.time";
Query query = session.createQuery(hql);
query.setDate("time", calend.getTime()); //calend is a Calendar object
然而,这不起作用。Error表示这是hql错误。请不要使用
setDate
尝试使用setParameter
从
“setDate”将截断HQL日期值并忽略小时、分钟、秒
使用
setParameter
会将值解释为指示的参数:变量因为您只使用一个表,请尝试不使用表别名。如果不使用表别名,我仍然会收到相同的错误。请尝试按小时分组(时间)
,看看这是否有帮助。
String hql = "select time, hour(time), minute(time) from db as O "
+ "where O.time >= :time group by 2 order by O.time";
Query query = session.createQuery(hql);
query.setDate("time", calend.getTime()); //calend is a Calendar object