我将 Hibernate 与 DB2 一起使用,并遇到以下问题。表/实体
Customer
具有字段 first_name
、last_name
、birthday
(java.util.Date
)。
我需要编写一个查询,它将检索在接下来的四天内过生日的所有客户。问题是,对于某些客户的出生年份是未知的,因此在数据库中将其设置为
9999
,因此,我不能只在where
子句中进行简单的检查(因为年份9999
)。
使用简单的 hql 查询
from Customer as user where month(user.birthday) = month(current_date()+4 days) and day(user.birthday) = day(current_date()+4 days)
union all
from Customer as user where month(user.birthday) = month(current_date()+3 days) and day(user.birthday) = day(current_date()+3 days)
union all
from Customer as user where month(user.birthday) = month(current_date()+2 days) and day(user.birthday) = day(current_date()+2 days)
union all
from Customer as user where month(user.birthday) = month(current_date()+1 day) and day(user.birthday) = day(current_date()+1 day)