Hi,
It appears the hibernate libraries don't recognize a valid query with the 'having' clause. I'm using Hibernate 3.2.2.ga and Hibernate annotations 3.2.1.ga. Here is the error I get:
Code:
12:20:34,793 ERROR [org.hibernate.util.JDBCExceptionReporter] Not in aggregate function or group by clause:
COLUMN MERCHANTSC0_.SCORE_DATE in statement [select merchantsc0_.mid as mid2647_, merchantsc0_.score_date as score2_2647_, merchantsc0_.avg_Avail as avg3_2647_, merchantsc0_.avg_CustS as avg4_2647_, merchantsc0_.avg_Ease as avg5_2647_, merchantsc0_.avg_Info as avg6_2647_, merchantsc0_.avg_Likely as avg7_2647_, merchantsc0_.avg_OverAll as avg8_2647_, merchantsc0_.avg_Price as avg9_2647_, merchantsc0_.avg_PrRep as avg10_2647_, merchantsc0_.avg_Prvcy as avg11_2647_, merchantsc0_.avg_Select as avg12_2647_, merchantsc0_.avg_Ship as avg13_2647_, merchantsc0_.avg_Site as avg14_2647_, merchantsc0_.score_kind as score15_2647_ from merchant_score merchantsc0_ where merchantsc0_.mid=? group by merchantsc0_.mid having merchantsc0_.score_date=max(merchantsc0_.score_date)]
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2214)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
at org.hibernate.loader.Loader.list(Loader.java:2090)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
Note that if I copy and paste the generated query above into my sql editor and run it in sybase, it works properly and returns data. Why doesn't hibernate think this is a valid query?