4
我需要幫助將一些sql轉換爲hibernate sql。將SQL查詢轉換爲Hibernate查詢
SQL:
String sql = "select time, hour(time) as hour, minute(time) as minute "
+ "from db where time >= DATE_ADD(now(), INTERVAL -24 HOUR) "
+ "group by 2 order by time LIMIT 500";
我用的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.setDate("time", calend.getTime()); //calend is a Calendar object
但是,這是行不通的。錯誤表示這是一個hql錯誤。
爲您只使用一個表,嘗試不使用表的別名。 –
我仍然得到相同的錯誤,如果我沒有表別名。 –
嘗試'GROUP BY小時(時間)',看看是否有幫助。 – knittl