Hibernate JPQL CURRENT_DATE不适用于SQL Server [英] Hibernate JPQL CURRENT_DATE not working on SQL Server
问题描述
我有以下JPQL查询:
SELECT x FROM Bla x WHERE x.deadline< CURRENT_DATE
这在MySQL上按预期工作。但SQL Server抱怨 CURRENT_DATE
未被识别。
我在问自己究竟是什么问题。然后 CURRENT_DATE
是一个标准的JPA函数,它应该独立于底层的RDBMS解析。
CURRENT_DATE
记录(请参阅: http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html/ch11.html#ql-expressions )。 我搜索了一下,发现很多评论告诉我,我将使用 CURRENT_DATE()
来代替。但这不是JPQL。
那么为什么 CURRENT_DATE
不起作用,解决方案是什么?
我正在使用Hibernate 4.1.8.Final。
祝好,
Florian
您可以尝试将当前日期作为参数传递给查询。
session.createQuery(SELECT x FROM TABLE_NAME x WHERE x.deadline< :currentDate)
.setParameter(currentDate,currentDate)
.list();
否则,您可以使用 current_date()$ c $而不是
current_date
,这是HQL表达式的一部分。
I have the following JPQL query:
SELECT x FROM Bla x WHERE x.deadline < CURRENT_DATE
This works as expected on MySQL. But SQL Server complains that CURRENT_DATE
is not recognized.
I am asking myself what exactly the problem is. Then CURRENT_DATE
is a standard JPA function that should resolve independent from the underlying RDBMS.
Further the Hibernate documentation also has CURRENT_DATE
documented (see here: http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html/ch11.html#ql-expressions).
I googled and found a lot fo comments telling me that I shall use CURRENT_DATE()
instead. But this isn't JPQL.
So why is CURRENT_DATE
not working and what is the solution?
I am using Hibernate 4.1.8.Final.
Best regards, Florian
You can try to pass current date as a parameter to the query. Also, there will no portability issue whith this.
session.createQuery("SELECT x FROM TABLE_NAME x WHERE x.deadline < :currentDate")
.setParameter( "currentDate", currentDate)
.list();
Else, you can try query with current_date()
instead of current_date
, which is part of HQL expression.
这篇关于Hibernate JPQL CURRENT_DATE不适用于SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!