-->
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: Comparing Dates
PostPosted: Tue Oct 28, 2003 5:53 am 
Newbie

Joined: Tue Oct 28, 2003 5:26 am
Posts: 2
Location: Zurich, Switzerland
Hi there

After playing a while around with Hibernate, I have a few
issues. Apart from that, it's a quite nice and easy-to-use tool,
the code-compile-test cycle is much shorter than usual!

I have a class containing a java.util.Date-Object, this
will be mapped to a DATETIME on my MySQL DB (4.0.14).
(Hibernate 2.0.3, Java 1.4.2)

Now the problem is: How can I compare 2 Dates ?
Quote:

Note: A Date shouldn't contain any Informations about the
current time, a Date consists only of Day, Month and Year.
Though, the java.util.Date Class contains informations
about the current time as well.


I tried it like:
Code:
session.find("from MyClass as myCls where cls.myDate = ?",
     new Date(), Hibernate.DATE);

But this always returns 0 results... (Yes, I have a few entries
for todays date ;))

The problem is that also the times will be compared... How can I avoid
this behaviour, because I'm only interested in the Date (Year, Month,
Day) ? Is there an easy solution for MySQL, or do I something wrong ?

Thanks in advance
"L


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2003 5:59 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Don't you mean to map this with type="date"?

If not, your database should have some function to truncate the datetime to a date. You may call this function in the HQL where clause. Then use Hibernate.DATE to bind the parameter, just like you did.


Top
 Profile  
 
 Post subject: Thanks for your fast and helpful response!
PostPosted: Tue Oct 28, 2003 6:10 am 
Newbie

Joined: Tue Oct 28, 2003 5:26 am
Posts: 2
Location: Zurich, Switzerland
Thanks for your fast and helpful response.

After adding the type="date" property to the XDoclet
comment it worked perfectly! The DB-Schema changed slightly
(from DATETIME to DATE) and even the query returned some
rows.

Great!

Thanks a lot
"L


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.