-->
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.  [ 5 posts ] 
Author Message
 Post subject: HQL: time interval query
PostPosted: Tue Sep 07, 2004 7:57 am 
Newbie

Joined: Fri Mar 05, 2004 9:19 am
Posts: 5
Hi there,

I would like to perform a query on object which contains Date attribute and limit result set to specified date-time period and then specify also the time interval. For example, I'm interested in all objects between date1 and date2 and then inside this time period I would like to get all objects between 12:00 and 14:00. I know how to get objects between two dates but how to limit result also to specified time period? It is very important to not fetch whole data between these two dates and then enumerate items and find which one match specified time period but perofor this directly in query. I've tried to access minutes and houres attributes in Date object in the query but without the success.

Thanks in advance,

Sebastian Gil


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 07, 2004 11:52 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
try using a specific function of your DB vendor

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 07, 2004 2:49 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
emmanuel wrote:
try using a specific function of your DB vendor


Our use two different properties to persist the date and time parts. You can then query them like this:

Code:
from MyEntity e where e.date >= :minDate and e.date < :maxDate and e.time >= :minTime and e.time < :maxTime


PS: make sure to use the DATE and TIME Hibernate types when mapping your properties...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 08, 2004 3:49 am 
Newbie

Joined: Fri Mar 05, 2004 9:19 am
Posts: 5
emmanuel wrote:
try using a specific function of your DB vendor


Thanks. I didn't know that Hibernate supports native SQL injection in HQL. Very powerful feature. Once again I'm very impressed on implementation.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 08, 2004 3:51 am 
Newbie

Joined: Fri Mar 05, 2004 9:19 am
Posts: 5
bertrand wrote:
emmanuel wrote:
try using a specific function of your DB vendor


Our use two different properties to persist the date and time parts. You can then query them like this:

Code:
from MyEntity e where e.date >= :minDate and e.date < :maxDate and e.time >= :minTime and e.time < :maxTime


PS: make sure to use the DATE and TIME Hibernate types when mapping your properties...


Thanks for the hint. Unfortunatelly I cannot modify anything in database. I have to support legacy system.


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