Adnan Alicic
Adnan Alicic

Reputation: 19

Retrieving all customers that have a birthday in the next four days in Hibernate

I use Hibernate with DB2 and have the following problem. The table/entity Customer has the fields first_name, last_name, birthday(java.util.Date).

I need to write a query, which will retrieve all customers that have a birthday in the next four days. The problem is that, for some customers the year of birth is unknown, so it was set to 9999 in database, and therefore, I can not just do a simple check in the where clause (because of the year 9999).

Upvotes: 1

Views: 3797

Answers (1)

Roman C
Roman C

Reputation: 1

Using the simple hql query

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)

Upvotes: 1

Related Questions