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

Steve Ebersole (JIRA) noreply at atlassian.com
Sat May 8 18:11:49 EDT 2010


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

Steve Ebersole edited comment on HHH-5173 at 5/8/10 5:11 PM:
-------------------------------------------------------------

One option is to alter the definition of the avg function in the HSQLDialect to use an explicit cast
{code}
registerFunction( "avg", new SQLFunctionTemplate( Hibernate.DOUBLE, "avg( cast( ?1 as double ) )" ) );
{code}

Note the checking done in the base Dialect version wrt the number of columns.

      was (Author: steve):
    One option is to alter the definition of the avg function in the HSQLDialect to use an explicit cast
{code}
registerFunction( "avg", new SQLFunctionTemplate( Hibernate.DOUBLE, "avg( cast( ?1 as double )" ) );
{code}

Note the checking done in the base Dialect version wrt the number of columns.
  
> 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