-->
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: Date range in HQL
PostPosted: Sun Mar 15, 2009 2:40 am 
Newbie

Joined: Sat Oct 11, 2008 7:28 am
Posts: 10
Location: New Delhi (INDIA)
Hi Friends,

I am trying to retrieve objects from database which are created in between two given dates.
I tried following query but no result and no exception, empty iteratator is returned by the query.list() method:

Code:
challans = session.createQuery("select h from ChallanPO as h where CUSTOMERID="+custID+" AND CREATIONDATE > "+"2008-10-1"+" AND CREATIONDATE < "+"2009-3-31").list();



ChallanPO stores date reference of type java.util.Date object.
and in database column CREATIONDATE is of type DATETIME.

Hibernate version:3.1

Name of the database you are using: mySql

[b]The generated SQL (show_sql=true):[br]
Hibernate: /* select h from ChallanPO as h where CUSTOMERID=1.0 AND CREATIONDATE > 2008-10-1 AND CREATIONDATE < 2009-3-31 */ select challanpo0_.CONSIGNMENT_ID as CONSIGNM1_4_, challanpo0_.CUSTOMERID as CUSTOMERID4_, challanpo0_.NOOFJOBS as NOOFJOBS4_, challanpo0_.DESTINATION as DESTINAT4_4_, challanpo0_.CREATIONDATE as CREATION5_4_, challanpo0_.SOURCE as SOURCE4_, challanpo0_.VEHICLE_NUMBER as VEHICLE7_4_, challanpo0_.CARRIER_ID as CARRIER8_4_, challanpo0_.INVOICE_ID as INVOICE9_4_, challanpo0_.ISINVOICED as ISINVOICED4_, challanpo0_.TAXAMOUNT as TAXAMOUNT4_, challanpo0_.TAXPERCENTAGE as TAXPERC12_4_, challanpo0_.VAT as VAT4_, challanpo0_.SUBTOTAL as SUBTOTAL4_, challanpo0_.GRANDTOTAL as GRANDTOTAL4_, challanpo0_.PAYMENTSTATUS as PAYMENT16_4_ from consignment challanpo0_ where CUSTOMERID=1.0 and CREATIONDATE>2008-10-1 and CREATIONDATE<2009-3-31
[b]


Please suggest.

_________________
Thanks,
Arun


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 15, 2009 5:21 pm 
Beginner
Beginner

Joined: Wed Jun 28, 2006 2:24 pm
Posts: 30
Location: Brazil
Try put the dates between quotes:

Code:
challans = session.createQuery("select h from ChallanPO as h where CUSTOMERID="+custID+" AND CREATIONDATE > "+"'2008-10-1'"+" AND CREATIONDATE < "+"'2009-3-31'").list();


2008-10-1 is equals to: 1997


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 21, 2009 11:50 am 
Newbie

Joined: Sat Oct 11, 2008 7:28 am
Posts: 10
Location: New Delhi (INDIA)
Thanks for your answer. it works!!

_________________
Thanks,
Arun


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.