hibernate-orm
hibernate-orm copied to clipboard
HHH-15228 ("RoundFunction" which extends StandardSQLFunction to return BigDecimal)
HHH-15228
"RoundFunction" which extends StandardSQLFunction to return BigDecimal
- support for round() function in H2 database to return BigDecimal if argument is BigDecimal
- By default, it would return Double
Thanks for your pull request!
This pull request appears to follow the contribution rules.
› This message was automatically generated.
Not sure I think we should be making piecemeal changes like this to Hibernate 5.
This is all already fixed Hibernate 6 where all this is much more well-defined, and if you're stuck on 5 you can pretty do this customization in your own project.
ROUND()
in modern versions of H2 (2.0.202 and newer) actually returns value of exactly the same data type as data type of its first argument, if it is a TINYINT
, SMALLINT
, INTEGER
, BIGINT
, REAL
, DOUBLE PRECISION
or DECFLOAT
. If it is a NUMERIC
(DECIMAL
), this function returns a NUMERIC
value with adjusted precision and scale.
In unsupported (on H2 side) H2 1.4.200 it returns value of the same data type for REAL
and DOUBLE PRECISION
arguments and DECIMAL
(NUMERIC
) for arguments of other data types.
In unsupported (on H2 side) H2 1.4.199 and older versions it returns a DOUBLE PRECISION
value unconditionally.
Old implementation looks like correct for H2 1.4.199 and older versions and incorrect for newer versions. Implementation proposed here looks like incorrect for all versions of H2, but it may work better anyway.
But the correct (portable) behavior is now defined by JPA, and is not something that is supposed to vary between databases.
Again, I don't think we need to be messing with the existing behavior in H5. This was all already carefully reviewed for H6.
@gavinking but it behaves differently with postgres. We are using postgres database production environment, it returns the data type same as argument, but H2 doesn't for same version of hibernate.
So currently, there are different behaviours for H2 and postgres (I assume others database as well).
Again: if you're talking about Hibernate 5 here, then yes, correct, there are very many things that are inconsistent between dialects on H5. These have been fixed in Hibernate 6, and I don't think it makes much sense to go back and try to fix them all in H5.
People who want better portability between databases should update to H6.