On 1/23/2011 5:29 AM, javabuddy wrote:
In the above scenario, I am trying to get the assignments that are due
on the current day, thats the reason I am sending new Date() as
parameter value.
A java Data object is a wrapper for a time in milliseconds. If a and b are Date objects, then a.equals(b) only when the millisecond time of a is exactly the same as the millisecond time of b.
If you are searching for the same day value you'll have to do something a bit 
cleverer with your query.

If you are using JPQL it seems to be seriously lacking the functions to select elements of the date. The best suggestion that I've seen is that in your DAO function you pass in two values, one for the first millisecond of the day and one for the last, and compare your actual date value to see if it lies between them.

The alternative, which depends upon your system configuration, is to use an SQL native query - depending upon the db you are using there are normally 'day' 'hour' 'minute' etc functions. For example in postgres, you can use EXTRACT(DAY FROM TIMESTAMP, 'date') - but that won't work in JPQL.

See here for a further discussion - at the end Quintin Beukes discusses it 
pretty well:

http://old.nabble.com/how-to-compare-2-dates-in-a-JPA-QL-query-td18959789.html

Regards

Alan

On Jan 22, 10:49 pm, zixzigma<[email protected]>  wrote:
I believe in the line below:
assignmentsDueForDay.setParameter("date", new Date(),TemporalType.DATE);

you are passing "new Date()", which is the current time/date on the system,
and is not the date you are looking for.
you need to pass the Date you are looking for, not the current time.

i've read in previous posts, that its better to create a DataTransferObject
for your Date (day/month/year).
and pass it to the server, because the time/date on the client would likely
be different than server (considering time zones)/

make sure you use an appropriate date, instead of new Date().

this is all I am guessing, I might be wrong.

--
You received this message because you are subscribed to the Google Groups "Google 
Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to