HI I wanted to run native SQL from hibernate (using createSQLQuery method) and this was working fine for a long time but found a strange issue today. just a single record is different compare to what is returned from the actual database.
results when the query returns from the db directly truncdate | count ---------------------+------- 2010-10-03 00:00:00 | 7438 2010-10-03 01:00:00 | 8848 2010-10-03 02:00:00 | 8867 2010-10-03 03:00:00 | 9874 2010-10-03 04:00:00 | 10255
results when the query returns from hibernate third raw allways get truncdate as 2010-10-03 03:00:00 (this is different what is returned in database 2010-10-03 02:00:00) - I'm truncating hourly so results should get for each hour starting from 00, 01, 02, 03, 04 etc -- but I allways get 00, 01, 03, 03, 04 .. etc. All the other count values are correct
below is the code StringBuilder strQuery = new StringBuilder(); strQuery.append("SELECT date_trunc('HOUR', event_date) as truncdate, sum(count_event) as count "); strQuery.append("FROM aggr.aggr_total_events WHERE event_name in ( 'Play' ) AND ( clientid=:clientid OR ownerid=:clientid ) "); strQuery.append (" AND event_date between '2010-10-03 00:00:00.0' AND '2010-10-03 23:00:00.0' "); strQuery.append("GROUP BY truncdate, event_name ORDER BY truncdate "); SQLQuery query = s.createSQLQuery(strQuery.toString()); query.addScalar("truncdate", Hibernate.TIMESTAMP); query.addScalar("count", Hibernate.INTEGER); query.setParameter("clientid", clientId); // Execute the query List<Object[]> results = query.list(); hibernate jars included in this project hibernate3.jar hibernate-annotations.jar hibernate-commons-annotations.jar
|