0

I have the following table in the database:

create table PERSON
(
    PERSON_ID bigint auto_increment primary key,
    BIRTHDAY date null,
    GENDER varchar(255) null,
    IDENTIFICATION varchar(15) null,
    LAST_NAME varchar(50) not null,
    NAME varchar(60) not null,
    constraint UK_7vkwh3506i8iq0ijvqoewdciy unique (IDENTIFICATION)
);

And I want to do the following SQL statement in JPA2

SELECT
  P.PERSON_ID,
  P.BIRTHDAY
FROM PERSON P
WHERE
  DATE_ADD(P.BIRTHDAY,
      INTERVAL (YEAR(CURDATE()) - YEAR(P.BIRTHDAY))
               + IF(DAYOFYEAR(CURDATE()) > DAYOFYEAR(P.BIRTHDAY), 1, 0) YEAR)
  BETWEEN
  DATE_ADD(CURDATE(), INTERVAL 1 DAY)
  AND
  DATE_ADD(CURDATE(), INTERVAL 7 DAY);

I can't find the way of using date_add SQL method and nest between the other SQL methods.

I need some help please. :)

  • JPA has weak support for date time functions. One reason for this is that the underlying date functions are highly database dependent. Workarounds include using only unix epoch time in your query, or running your query as a native SQL query. – Tim Biegeleisen Aug 01 '17 at 01:36
  • or a stored procedure – Scary Wombat Aug 01 '17 at 01:42

0 Answers0