Taking the difference of temporal fields in JPQL

倾然丶 夕夏残阳落幕 提交于 2019-12-25 07:59:05

问题


I have an entity Event which has fields startDate and endDate. I'd like to select only those events that have at most x days left to the their endDate. I want to do this in JPQL and with only one query. How can I do this?


回答1:


JPA does not provide any standard date/time functions. You can use a native SQL query using SQL EXTRACT,

Or, if you are using EclipseLink you can use the FUNC JPQL operator to call a database specific function, or use EXTRACT if using EclipseLink 2.4,

See,

http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/JPQL#Functions



来源:https://stackoverflow.com/questions/10578597/taking-the-difference-of-temporal-fields-in-jpql

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