-->
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.  [ 4 posts ] 
Author Message
 Post subject: Query record between fromDate and toDate - no record found
PostPosted: Fri Jul 13, 2007 11:59 am 
Newbie

Joined: Tue Jun 26, 2007 10:37 am
Posts: 5
Hello All,
My query below is working:

Code:
Date fr, to;
Calendar cal = Calendar.getInstance();
   cal.set(2007, 8, 10, 0, 0);
   fr = cal.getTime();
   cal.set(2007, 8, 11, 0, 0);
   to = cal.getTime();
 

Object[] parameters = { groupId, fr};

"from WebFile Wf where Wf.groupId = ? " + "and Wf.creationTimestamp >= ?"


but not with this:
Code:
Object[] parameters = { groupId, fr, to};

"from WebFile Wf where Wf.groupId = ? " + "and Wf.creationTimestamp >= ? and Wf.creationTimestamp <= ?"



and still not working with this either:
Code:
"from WebFile Wf where Wf.groupId = ? " + "and Wf.creationTimestamp between ? and ?"



Do you see anything wrong w/ the query string above? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 13, 2007 12:48 pm 
Newbie

Joined: Tue Jun 26, 2007 10:37 am
Posts: 5
I tried with the following, but still, the webFileList is empty:
Code:
HibernateDaoSupport
webFileList = this.getSession().createCriteria(com.wu.wads.model.WebFile.class).
         add(Expression.between("creationTimestamp",fr, to)).list();



Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 13, 2007 1:32 pm 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
Hi trungu

I think you'll find your calendar setup is at fault - it represents a date 2 months in the future:

cal.set(2007, 8, 11, 0, 0);
fr = cal.getTime();
System.out.println(fr);

-> Tue Sep 11 00:00:38 BST 2007

Mike


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 13, 2007 1:57 pm 
Newbie

Joined: Tue Jun 26, 2007 10:37 am
Posts: 5
Thanks thatmikewilliams, but I solved my problem as below. Hope it will help someone later.
Basically, the hour and minute of "to" date should 23 and 59 respectively.
Code:
        cal.set(2007, 8, 11, 23, 59);
        to = cal.getTime();


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