Hi,
rounding should be part of your domain logic and not driven by truncation or some magic rounding on the mapping level.
So best handle the rounding directly in the property setter or somewhere in the domain logic even before setting the property.
Otherwise you may get strange results if you use the property value for further calculations. When freshly setting the property to 112,355 and doing some calculation, e.g. *10 you get an amount of 1223,55.
But after reading the rounded value from the database, the same calculation will give you 1223,60. This violates the principle that persistence should be somewhat transparent.
Am Dienstag, 18. Dezember 2012 17:30:45 UTC+1 schrieb Iiro Rahkonen:
Hi!
I have an issue with rounding numbers to the database.
I have a mapping property and the database has datatype decimal(18,2) on the field.
<property name="Amount" column="Amount" not-null="true" precision="18" scale="2" />
I would like to add a rounding function to the property mapping so that number like 112,355 would be 112,36 instead of the result of the current truncation of the number 112,35.
Basicly use the round function in .NET or SQL Server when inserting the value. Is this possible in the mapping file or do I have to do the change everywhere where the value is inserted in the database?