users@glassfish.java.net

RE: Re: problem with JPA query for date handling

From: Deepu Syamaladevi Janardhananachary (UST, IND) <"Deepu>
Date: Tue, 6 Jul 2010 12:44:27 +0530

Hi

Will this be okay for you?

Calendar startDate = GregorianCalendar.getInstance();
Calendar endDate = GregorianCalendar.getInstance();

Query query = em.createQuery("SELECT e FROM EmployeePp e WHERE e.eventinstanceid = :eventInstance AND e.enddate >= :startdate AND e.startdate <= :enddate Order By e.startdate");
           query.setParameter("eventInstance", eventInstance);
      query.setParameter("startdate", startDate, TemporalType.TIMESTAMP);
      query.setParameter("enddate", endDate, TemporalType.TIMESTAMP);
      
  @SuppressWarnings("unchecked")
        List<EmployeePp> foundEvents = (List<EmployeePp>)query.getResultList();



Regards,
Deepu Janardhananachary


-----Original Message-----
From: glassfish_at_javadesktop.org [mailto:glassfish_at_javadesktop.org]
Sent: Monday, July 05, 2010 11:24 PM
To: users_at_glassfish.dev.java.net
Subject: Re: problem with JPA query for date handling

continuation of the query:
But the result is not as expected. It looks like it gives all results always. I am not getting records as i wish (greater than today or between two given date). When i googled, i feel the problem is the date sent from java is java Date format like Thu Jul 01 00:00:00 CEST 2010 whereas the data is DB is stored in Oracle Date format like 01-JUL-10.

So I feel we need to convert the date value before sending to oracle. I tried simpledateformat conversion, to_date, to_char, DATE() but they all work in native query and fails in JPAQL. Can someone suggest how to resolve the problem?
[Message sent by forum member 'kewlbuddy']

http://forums.java.net/jive/thread.jspa?messageID=476810

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
For additional commands, e-mail: users-help_at_glassfish.dev.java.net