不同数字的Hibernate BigDecimal转换错误

时间:2016-07-18 14:10:16

标签: java spring hibernate db2

当我尝试使用BigDecimal fazlaBulundurmaOrani = new BigDecimal(6000);时,我有一个成功插入表的测试类。但是,对于不同的BigDecimal值(例如BigDecimal fazlaBulundurmaOrani = new BigDecimal(15000);

),此测试失败

这是我的测试用例:

@Test
public void testGetDepoFazlaById() {
    DepoTur depoTur = new DepoTur("my tür", 5);
    depoTurService.saveDepoTur(depoTur);

    List<DepoTur> list = depoTurService.getDepoTurList();
    assertNotNull(list.get(0));

    BigDecimal fazlaBulundurmaOrani = new BigDecimal(6000);
    DepoFazla depoFazla = new DepoFazla(1, list.get(0), fazlaBulundurmaOrani);
    depoFazlaService.saveDepoFazla(depoFazla);
}

以下是模型中的hibernate引用:

@Column(name = "FAZLABULUNDURMAORANI", nullable = false, columnDefinition = "DECIMAL(6, 2)")
@Type(type = "big_decimal")
private BigDecimal fazlaBulundurmaOrani;

以下是我创建数据库的方法:

CREATE TABLE PGMTEMS.TDEPOFAZLA
(
    ID DECIMAL(20,0) GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
    GRUP INTEGER NOT NULL,
    DEPOTUR DECIMAL(20, 0) NOT NULL,
    FAZLABULUNDURMAORANI DECIMAL(6, 2) NOT NULL,
    PRIMARY KEY (ID)
)

当我尝试使用不同的BigDecimal数字时,我收到此错误:

  

org.springframework.jdbc.UncategorizedSQLException:Hibernate   操作:无法插入:[tr.gov.tcmb.pgmtems.model.DepoFazla];   未分类SQL的SQLException [插入PGMTEMS.TDEPOFAZLA   (ID,DEPOTUR,FAZLABULUNDURMAORANI,GRUP)值(默认值,?,?,?)];   SQL状态[null];错误代码[-4220];

1 个答案:

答案 0 :(得分:0)

我已设置FAZLABULUNDURMAORANI DECIMAL(6, 2),因此它的值可能为9999,00。 15000有四位以上,因此会出错。