hibernate-orm icon indicating copy to clipboard operation
hibernate-orm copied to clipboard

HHH-15228 ("RoundFunction" which extends StandardSQLFunction to return BigDecimal)

Open mayur-bhindi opened this issue 2 years ago • 6 comments

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

mayur-bhindi avatar Apr 25 '22 16:04 mayur-bhindi

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.

gavinking avatar May 04 '22 20:05 gavinking

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.

katzyn avatar May 07 '22 04:05 katzyn

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 avatar May 07 '22 07:05 gavinking

@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).

mayur-bhindi avatar May 07 '22 08:05 mayur-bhindi

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.

gavinking avatar May 07 '22 08:05 gavinking