-->
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.  [ 2 posts ] 
Author Message
 Post subject: Date Comparison
PostPosted: Tue Aug 15, 2006 11:09 pm 
Newbie

Joined: Tue Jul 11, 2006 10:41 pm
Posts: 11
Hi ,

let's say i have this sql which is comparing only date without time against oracle
select * from some_table where to_char(creation_date,'yyyymmdd') = '20060606'

/
select * from some_table where creation_date = to_date('20060606','yyyymmdd')

Both are working but when i use Criteria API in Hibernate it does not work
I believe this because when i construct the Date() in Java it appends the time as well

How do i ignore the time and construct it and pass it to Criteria
Can give me example.
Thanks.

below are my Criteria Code
Code:
Criteria criteria = session.createCriteria(some_table.class);
  criteria.add(Restrictions.eq("creation_date",DATE OBJECT);


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 12:33 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I think that passing in a java.sql.Date instead of a java.util.Date should work, as SQL dates really are dates, not date and time.

If that doesn't work, you can use HQL, which has the useful functions second(...), minute(...), hour(...), day(...), month(...), year(...) built in.

Finally, you could be explicit and add two comparisons: >= startOfDate && <= endOfDate.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.