I use Hibernate JPA in my backend. I am writing unit test using JUnit and DBUnit to insert a dataset into an in-memory HSQL database.
My dataset contains:
<order_line order_line_id="1" quantity="2" discount_price="0.3"/>
What the OrderLine Java object displays, where the discount_price column is defined as:
@Column(name = "discount_price", precision = 12, scale = 2) private BigDecimal discountPrice;
However, when I run my test case and claim that the discount price returned is 0.3, the statement fails and says that the stored value is 0. If I change the discount_price in the dataset to 0.9, it is rounded to 1.
I made sure that HSQLDB does not perform rounding, and this is definitely not because I can insert an order line object using Java code with a value of 5.3, and it works fine.
It seems to me that DBUtils for some reason rounds the number I determined. Is there a way to make this not happen? Can anyone explain why this can be done?
Thanks!
source share