10 位 BigDecimal 无法保存在 NUMBER(10, 2) 列中

10-digits BigDecimal cannot be saved in NUMBER(10, 2) column

在 Oracle 12 数据库中,我的其中一个列是用 NUMBER(10,2) 定义的。目标是存储这样的数字:12345678.12。实际上,我可以存储这样的数字感谢 Oracle SQL Developer,所以格式匹配。

通过我的 Hibernate-Java 应用程序,当我更新包含以下值的实体时,它起作用了:

1.12
12.12
123.12
1234.12
12345.12
123456.12

但是对于以下内容,我得到一个错误

1234567.12
12345678.12

ORA-01438: value larger than specified precision allowed for this column

它看起来像一个 NUMBER(8, 2)...

该字段在@Embeddable class 中,类型为 BigDecimal,没有任何字段注释:

@Entity
@Table(...)
public class ClassA implements Serializable {

    @Embedded
    private ClassB bObject;
}

@Embeddable
public class ClassB implements Serializable {

    @Embedded
    private ClassC cObject;
}

@Embeddable
public class ClassC implements Serializable {

    private BigDecimal myField;
}

是否有任何其他东西可以覆盖我的列定义?

小数类型的第一个数字是精度,第二个数字是小数位。
来自 Oracle 的文档:

You can specify the precision (the total number of digits, both to the left and the right of the decimal point) and the scale (the number of digits of the fractional component).

如果分数前有 10 位数字,则需要 DECIMAL(12,2).

您看到的错误来自 Oracle,而不是 Hibernate,因此我怀疑更改您的实体配置能否解决您的问题。

感谢@Guillaume F.,我启用了 log4j 的跟踪日志记录,我发现错误发生在审计 table 中,它不是最新的。列定义仍然是 NUMBER(8,2) 而不是 NUMBER(10,2)