JPA日期算术? [英] JPA Date Arithmetic?
问题描述
可以使用JPA / Hibernate执行日期算术吗?例如,我有一个具有java.util.Date字段的实体,指示行何时被创建。是否可以使用JPQL执行查询并在该字段中包括日期算术?例如,可以在该字段中执行COUNT(*)行,然后按GROUP BY执行吗?可以执行其他功能,例如只返回查询中该字段的月份或年份?
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?
推荐答案
HQL确实有日期表达式,如 second(...)
,分(...)
,小时(...)
, day(。 ..)
, month(...)
和 year(...)
但是标准JPQL没有这样的功能。
HQL does have date expressions like second(...)
, minute(...)
, hour(...)
, day(...)
, month(...)
, and year(...)
but standard JPQL doesn't have such functions.
这篇关于JPA日期算术?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!