我創建簡單的@NamedQuery在實體:的Java NamedQuery並設定日期參數
@NamedQueries({
@NamedQuery(name = ProductChangeLog.GetByDate, query = "From ProductChangeLog where date = :date ")
})
日期是Date.sql
,我想執行這個查詢:
List<ProductChangeLog> productChangeLogs = session.getNamedQuery(ProductChangeLog.GetByDate)
.setString("date", date)
.list();
我的問題是,這@NamedQuery產生查詢:
Hibernate: select productcha0_.id as id21_, productcha0_.availible as availible21_, productcha0_.category as category21_, productcha0_.date as date21_, productcha0_.description as descript5_21_, productcha0_.name as name21_, productcha0_.partnerId as partnerId21_, productcha0_.price as price21_, productcha0_.producent as producent21_, productcha0_.productId as productId21_, productcha0_.productUrl as productUrl21_, productcha0_.status as status21_ from ProductChangeLog productcha0_ where productcha0_.date=2014-01-20
這個查詢是錯誤的,cose日期應該在「」中,像這樣:productcha0_.date =「2014-01-20」
我該怎麼辦?
我已經試過
.setDate("date", date)
.setParameter("date", date)
而且門檻不工作。
你可以發佈任何堆棧跟蹤?你在查詢中錯過了「SELECT」關鍵詞嗎? – CycDemo
這是HQL,我不必添加SELECT。 – Ilkar
沒有堆棧跟蹤 - 我沒有這個查詢的結果。 – Ilkar