Did you try Mike's answer?
Date now = new Date();
Date thirtyDaysAgo = new Date(now.getTime() - (30 * MS_IN_DAY));
Query q = em.createQuery("Select m from Message m "
+ "where m.targetTime < :now and m.targetTime > :thirtyDays");
q.setParameter("now", now);
q.setParameter("thirtyDays", thirtyDaysAgo);
List<Message> results = (List<Message>) q.getResultList();
On Thu, May 5, 2011 at 4:35 PM, ram <[email protected]> wrote:
> Hi,
> I am trying to implement sysdate-5 in jpa.
>
> select *From emp where joinDate > sysdate-5
>
> The problem is in db schema, join date is defined as date, but in
> jpa entites, we have made it as TimeStamp by using @temporal so the it can
> store exact timestamp.
>
> when i tried to query by using @namedQuery, i am getting older than 5
> days. But i need data which is just 5 days old.
> I followed the following link
>
> http://stackoverflow.com/questions/2539035/how-to-do-a-timestamp-comparison-with-jpa-query
>
> but still i am getting same problem. Any ideas on this.
>
>
> Thanks
>
>
>