我创建简单的@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