-->
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: time insensitive date comparison in WHERE clause
PostPosted: Thu Jul 08, 2004 2:53 am 
Newbie

Joined: Wed Jul 07, 2004 8:30 am
Posts: 2
I have trouble getting the following query to return anything at all:

final Query query = session.createQuery(
" FROM FXRate AS fxr "
+ " WHERE fxr.baseCurrencyId = :base "
+ " AND fxr.ratedCurrencyId = :rated "
+ " AND fxr.effectiveDate = :date"
);
query.setParameter("base", base.getId());
query.setParameter("rated", rated.getId());
query.setParameter("date", calendar);

Yet I know that the combination of values I pass exists in the database.

Only if I first do this, I get what I want:

calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);

THAT IS, if I happen to do my coding before 12:00AM. After that, I have to write:

calendar.set(Calendar.HOUR, 12);

Things cannot be this ugly, can they? Am I overlooking something? I use "calendar_date" as the type of the date, but have also tried "calendar" and "date". Also note that the object has a composite key with a date as one of its components, so I overrode equals() and hashcode(). In the equals() method I just do

"this.calendar.equals(other.calendar)"

to compare the date component of the composite key.

Anyone any clue?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 08, 2004 4:32 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Use some SQL function or cast:

Code:
DATE_PART(fxr.effectiveDate) = DATE_PART( :date )


It must not be a problem with index in your case, you can create index for function in some databases too.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 08, 2004 7:20 am 
Newbie

Joined: Wed Jul 07, 2004 8:30 am
Posts: 2
Thanks! I will try that


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.