BigDecimal precision not persisted with javax.persistence annotations

Posted by dkaczynski on Stack Overflow See other posts from Stack Overflow or by dkaczynski
Published on 2012-06-08T21:07:35Z Indexed on 2012/06/09 10:40 UTC
Read the original article Hit count: 369

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.

© Stack Overflow or respective owner

Related posts about hibernate

Related posts about jpa