-->
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: Problem Comparing Dates
PostPosted: Thu Nov 16, 2006 4:33 am 
Newbie

Joined: Thu Nov 16, 2006 4:16 am
Posts: 1
I have a problem comparing dates with oracle, and i don't know how can I compare dates in the hql sentence.

I Put the source code:
Date iniDate = getIniDate(); //this obtains date in Spanish format: DD/MM/YYYY HH:mm:ss for example: 14/11/2006 10:00:00
Date endDate = getEndDate(); //this obtains date in the same format. For example: 15/11/2006 12:00:00 (In The database the dates are in the spanish format too)

//I want to obtain the Users born between these dates. I do this:

session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Query query = session.createQuery("from User where birddate>=? and birddate<?");
query.setParameter(0, iniDate);
query.setParameter(1, iniDate);
List lst = query.list();

This not obtains only the users born between this dates. Why?
I know that I can obtain all the users, get the birddate and then compare it, but I have a lot of registers, and I think this is a dirty solution.
How can obtain only the registers between 2 dates?

_________________
-Blaine-


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 10:43 am 
Beginner
Beginner

Joined: Thu Aug 24, 2006 6:01 am
Posts: 49
Location: sophia-antipolis, France
Have you tried changing your second iniDate to endDate?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 11:13 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi,

Try using Criteria.. I have not used between in HQL..
eg:)
List result=session.createCriteria(User.class)
.add( Restrictions.between("birddate", minDate, maxDate) )
.list();

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


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.