在JPA查询中使用CURRENT_DATE的示例 [英] Example of using CURRENT_DATE in JPA query
本文介绍了在JPA查询中使用CURRENT_DATE的示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以给我指出一个如何在JPA查询中使用CURRENT_DATE
的示例吗?
Can anyone point me to an example on how to use CURRENT_DATE
in a JPA query?
CURRENT_DATE
,但是我无法使其工作.我总是得到unexpected token [CURRENT_DATE]
异常.由于JPA中已指定该标准,因此所有提供商都应遵守该标准吗?
CURRENT_DATE
is specified in JPA but I haven't been able to make it work. I always get the unexpected token [CURRENT_DATE]
exception. Since it is specified in JPA all providers should comply with it right?
我正在使用EclipseLink 2.0 BTW.
I'm using EclipseLink 2.0 BTW.
推荐答案
它可以像这样使用:
Query query = manager
.createQuery("SELECT c FROM CITIES c WHERE c.founded = CURRENT_DATE");
for (Object city : query.getResultList()) {
System.out.println(city);
}
...其中 founded 是时间类型:
...where founded is a temporal type:
@Column(name = "FOUNDED")
@Temporal(TemporalType.DATE)
private Date founded = new Date();
不是一个很好的例子,但是您明白了.我正在使用Eclipselink 1.1.2
这篇关于在JPA查询中使用CURRENT_DATE的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文