BigDecimal precision not persisted with javax.persistence annotations
- by dkaczynski
I am using the javax.persistence API and Hibernate to create annotations and persist entities and their attributes in an Oracle 11g Express database.
I have the following attribute in an entity:
@Column(precision = 12, scale = 9)
private BigDecimal weightedScore;
The goal is to persist a decimal value with a maximum of 12 digits and a maximum of 9 of those digits to the right of the decimal place.
After calculating the weightedScore, the result is 0.1234, but once I commit the entity with the Oracle database, the value displays as 0.12.
I can see this by either by using an EntityManager object to query the entry or by viewing it directly in the Oracle Application Express (Apex) interface in a web browser.
How should I annotate my BigDecimal attribute so that the precision is persisted correctly?
Note: We use an in-memory HSQL database to run our unit tests, and it does not experience the issue with the lack of precision, with or without the @Column annotation.