-->
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.  [ 2 posts ] 
Author Message
 Post subject: HQL query
PostPosted: Thu Sep 18, 2008 11:29 am 
Newbie

Joined: Thu Sep 18, 2008 11:18 am
Posts: 2
Location: Ukraine
Hello!
I am writing an application that uses Hibernate.
And I need a specific HQL query:

select count(distinct date(o.date)) from MyObject o;

As you see, I want to select all unique dates.
The problem is that date property of the class MyObject represents date and time,so if I use following select count(distinct o.date) from MyObject o; I do not get what I really need.
So hibernate doesn't like that date function, that converts from dateTime to date.
Any ideas? Help please!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 4:23 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
fevzi,

The Date type in Oracle and others does store date and time, despite its name. If the time is not indicated, 12:00 midnight is used.
Therefore, a SELECT DISTINCT by that field alone, if you never specify time, should return different dates only.

If your time is also specified, but you want to achieve a distinct by date only, you can use Hibernate HQL's supported functions day() , month() and year(), and peform a SELECT DISTINCT by those.

_________________
Gonzalo Díaz


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