Java 如何在 JPA 命名查询上获取 CURDATE() / NOW()?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1500397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to obtain CURDATE() / NOW() on a JPA named query?
提问by albemuth
I want to do a select from table where date = TODAY, on mysql that would be where date > CURDATE()
, how do I do this on a JPA named query?
我想从表中选择日期 = TODAY,在 mysql 上,where date > CURDATE()
我如何在 JPA 命名查询上执行此操作?
采纳答案by ChssPly76
That depends on your JPA provider. Hibernate, for example, supports current_date()function:
这取决于您的 JPA 提供商。例如,Hibernate 支持current_date()函数:
from MyEntity where myDateProperty > current_date()
回答by McDowell
From the spec:
从规范:
4.6.16.3 Datetime Functions
functions_returning_datetime:= CURRENT_DATE | CURRENT_TIME | CURRENT_TIMESTAMP
The datetime functions return the value of current date, time, and timestamp on the database server.
4.6.16.3 日期时间函数
functions_returning_datetime:= CURRENT_DATE | CURRENT_TIME | CURRENT_TIMESTAMP
datetime 函数返回数据库服务器上的当前日期、时间和时间戳的值。