How can I tell hibernate to return a floating point 0.5 for this query?
Code:
select distinct (1 / 2) from Dataset
But instead of 0.5 hibernate returns 0 for this query, although the generated MySQL query
Code:
select distinct 1/2 as col_0_0_ from Dataset dataset0_
returns already a floating point. So it seems that hibernate converts the floating point value into an integer before returning to the user and the question is how to get rid of that.
A unpleasant workaround could be the casting to a string:
Code:
select distinct cast((1 / 2) as string) from Dataset
Then hibernate returns the string "0.5000" and we only have to cast it back to double or float. But this is really a hack IMO. I also tried to cast the value to float/double within the query but then hibernate constructs a query that MySQL does not understand, i.e. it contains "cast(... as float)".