[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-5173) hql - average returns double but looses the decimal part

Pascal Thivent (JIRA) noreply at atlassian.com
Sat May 8 20:12:49 EDT 2010


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5173?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=36988#action_36988 ] 

Pascal Thivent commented on HHH-5173:
-------------------------------------

H2 has the same "problem" (mentioned in [this question and answer|http://stackoverflow.com/questions/2791378/does-the-jpql-avg-aggregate-function-work-with-integers/2791841#2791841] on stackoverflow.com). The documentation of the [AVG|http://www.h2database.com/html/functions.html#avg] function of H2 writes: _The returned value is of the same data type as the parameter_. 

Personally, I think that Hibernate does its job, it returns a {{Double}} (and I couldn't find anything about the expected behavior of AVG in SQL-99 so I don't know if we can call this a bug in HSQLDB or H2 and other databases with the same behavior). But it would clearly make sense to return a value with a decimal part even for INT column types at the SQL level. So indeed, it would be nice to do a cast in the dialect to avoid having to run a native query for these databases. 

> hql - average returns double but looses the decimal part
> --------------------------------------------------------
>
>                 Key: HHH-5173
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5173
>             Project: Hibernate Core
>          Issue Type: Bug
>    Affects Versions: 3.5.0-Final
>         Environment: Database driver: hsqldb
> OS: Mac-Os
> Hibernate: 3.5.0-Final
>            Reporter: Sébastien Peters
>         Attachments: patch_unit_test.txt
>
>
> HQL:
>  select avg(r.rating) from Review r
>  for the values 2,2,2,1,2 it should return 1.8 instead of 1.0
> type of rating: integer

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       



More information about the hibernate-issues mailing list