-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Same day Date Based Search not returning expected result
PostPosted: Wed Jul 13, 2005 2:41 am 
Newbie

Joined: Mon Feb 28, 2005 2:10 am
Posts: 5
Hibernate version: 2

Name and version of the database you are using: Oracle 8

I am running a date based search where i am trying to find records within a certain time range, however when I specify a start and end date/time that occur on the same day as the record I am expecting in the result, it doesn't come back

ie.
Database table foo:
record1, startDate = 01/10/2005 10:00:00

HQL:
from foo as obj where obj.startDate >= ? and obj.startDate <= ?

where arg 1 is a date:
01/10/2005 00:00:01

and arg 2 is a date:
01/10/2005 23:59:59

No result returned.

The weird thing is, when I set arg 2 to the following day (02/10/2005 23:59:59), the record is correctly returned?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 13, 2005 9:31 am 
Senior
Senior

Joined: Tue Jun 21, 2005 10:18 am
Posts: 135
Location: South Carolina, USA
What method are you using to set your parameters on the query?

It sounds like you're losing your time information when you set your parameters. Are you using setDate()? If so, you might try converting your parameters to TimeStamps and using setTimeStamp(). Not sure how setDate() is supposed to behave, though....


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 13, 2005 7:51 pm 
Newbie

Joined: Mon Feb 28, 2005 2:10 am
Posts: 5
I was using setDate() and using setTimeStamp() has resolved my problem!

Thanks heaps!

I didn't know about setTimestamp(). I assumed that because my database mapping in my hibernate mapping file (see below) contained a timestamp, using the setDate() method would perform time based comparisons (Wrong). The Hibernate API (Query object) is not particularly helpful with documentation on these methods.

<property name="startDate" type="timestamp" column="START_DATE" not-null="true" />


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.