Hello,
I am trying to select a list of unique dates from a table, and I want those dates rounded to a day.
Example:
2004
2003
....
I am trying to use the following HQL:
Code:
Query q = ses.createQuery("select "
+ " {fn date_part('year', table.addDate)}"
+ " from uus "
+ " join uus.userInfo.foos as foos"
+ " where uus.bar.id =:barId"
+ " order by"
+ " {fn date_part('year', table.addDate)} desc");
This is run against a PostgreSQL database, which provides date_part() function.
The above query does not work in Hibernate, though, because of bad syntax:
Caused by: net.sf.hibernate.QueryException: undefined alias: {fn select {fn date_part(........
I thought, after reading/searching this forum, that {fn ....} would do it.
How do I run queries that use database functions from Hibernate?
I found a few posts that mentioned {fn ...} syntax, but this does not seem to work for me (Hibernate 2.1 final).
I also saw Christian's post from October 2003 that says this is in the docs, but I haven't been able to find it.
Can you see something wrong with my query?
Thank you,
Otis