How to obtain CURDATE() / NOW() on a JPA named query?

為{幸葍}努か 提交于 2020-06-11 16:49:45

问题


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?


回答1:


That depends on your JPA provider. Hibernate, for example, supports current_date() function:

from MyEntity where myDateProperty > current_date()



回答2:


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.



来源:https://stackoverflow.com/questions/1500397/how-to-obtain-curdate-now-on-a-jpa-named-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!