views:

34

answers:

1

Hi

I have a java.util.Date field in an @Entity and would like to get the distinct months from that column.

Suppose I only had three rows, with 14/07/2010, 24/11/1975 and 03/11/1975 (European date format - day/month/year), I would like to get the following back from Hibernate to go into a dropdown for filtering the data:

07/2010
11/1975

(or corresponding Date objects with the other fields set to zero - to be honest precisely how the data comes back isn't too important as I can work around that).

I'm guessing a database-agnostic approach in HQL isn't possible - any suggestions?

Rich

+1  A: 

What about :

select distinct month(c.birthday), year(d.birthday) from Cat c
Pascal Thivent
Thanks, I wasn't expecting it to be so simple!
Rich
@Rich You're welcome.
Pascal Thivent