JPA Date Arithmetic?

与世无争的帅哥 提交于 2019-12-01 18:24:36

问题


Is it possible to perform date arithmetic using JPA/Hibernate? For example, I have an entity with a java.util.Date field indicating when the row was created. Is it possible to perform a query using JPQL and include date arithmetic on that field? For example, can I perform a COUNT(*) of rows and then GROUP BY the month in that field? Can I perform other functions, such as only return the month or year from that field in a query?


回答1:


HQL does have date expressions like second(...), minute(...), hour(...), day(...), month(...), and year(...) but standard JPQL doesn't have such functions.



来源:https://stackoverflow.com/questions/2905785/jpa-date-arithmetic

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