Could you help me to understand the purpose of the ‘MONEY’ data type ? What is the use case ?
Because in java when I get a Map<String, Object> and want to get value from MONEY column I have to cast the value object to Integer or Double (depending on whether the value contains decimals). So it’s not always the same casting which is not practical.
Hi. The MONEY column is just a DECIMAL type under the hood, but with fixed decimalScale = 2.
In java it corresponds to the BigDecimal type.
Working with the money calculation you should always prefer the BigDecimal or at least the double (8 byte) type, not the integer.
Thank you for the clarification on the MONEY type.
However, I notice that it is possible to store an integer in a column of type double or money. This is problematic because when retrieving a value from a double or money column in Java we expect to retrieve a value of the type of the column. Currently it is therefore possible that a double column returns an integer value which generates an exception when casting the value to the real type (double) of the column. Normally the value passed to a column of type double should be converted to a double to avoid this problem.
As far as I understand, to work with the Money column type
use BigDecimal.valueOf(value) when getting values and there will be no errors in casting regardless of whether ‘value’ is of Integer or Double type
Yes of course it’s possible to do as you suggest but if it’s the only way to do it, I guess it’s not possible to use the “Custom Class” mapping ? Because you would need to use a specific type for each class properties unless you use the generic “Object” type for all double or money type columns, which doesn’t seem very practical to me.