Putting BigDecimal data into HSQLDB test database using DbUnit
- by Denise
Hi everyone,
I'm using Hibernate JPA in my backend. I am writing a unit test using JUnit and DBUnit to insert a set of data into an in-memory HSQL database.
My dataset contains:
<order_line order_line_id="1" quantity="2" discount_price="0.3"/>
Which maps to an OrderLine Java object 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 assert that the discount price returned equals 0.3, the assertion fails and says that the stored value is 0. If I change the discount_price in the dataset to be 0.9, it rounds up to 1.
I've checked to make sure HSQLDB isn't doing the rounding and it definitely isn't because I can insert an order line object using Java code with a value like 5.3 and it works fine.
To me, it seems like DBUtils is for some reason rounding the number I've defined. Is there a way I can force this to not happen? Can anyone explain why it might be doing this?
Thanks!