BigDecimal accuracy not persisted with JPA annotations

I use the javax.persistence API and Hibernate to create annotations and persistent entities and their attributes in an Oracle 11g Express database.

I have the following attribute in essence:

@Column(precision = 12, scale = 9) private BigDecimal weightedScore; 

The goal is to store a decimal value with a maximum of 12 digits and no more than 9 of these digits to the right of the decimal point.

After calculating weightedScore result is 0.1234, but as soon as I pass the object with the Oracle database, the value will be displayed as 0.12.

I can see this by using the EntityManager object to request a record or view it directly in the Oracle Application Express (Apex) interface in a web browser.

How do I annotate my BigDecimal attribute so that accuracy is maintained correctly?

Note. We use the in-memory HSQL database to run our unit tests and do not experience problems with lack of accuracy with or without @Column annotation.

Update:

When looking at the table description, the definition of the column weightedScore NUMBER(19, 2) . I also tried changing the annotation to @Column(columnDefinition="Number(12, 9)") , but this did not affect. Does anyone know why Oracle is not responding to these annotations?

+8
precision oracle11g hibernate jpa bigdecimal
source share
2 answers

I have found the answer. Hooray!

I tried to execute the following query through the Oracle Apex interface:

alter table NODE modify (WEIGHTEDSCORE NUMBER(12, 9));

I got an error stating that the column containing the data cannot be resized to have less precision or a smaller scale. That was my problem!

Since I was trying to modify a table with existing data, I had to either drop the table, or reinitialize it, or change the column to have more precision and scale.

I successfully completed the following request:

alter table NODE modify (WEIGHTEDSCORE NUMBER(26, 9));

We believe that I want to add 7 precision points to the right of the decimal point, so I add 7 to the overall accuracy to compensate for the zoom. Thus, a column can preserve all existing precision to the left of the decimal point, adding precision to the right.

+5
source share

It seems you are not the only one who has problems with this: http://www.eclipse.org/forums/index.php/m/716826/

+1
source share

All Articles