【问题标题】:Hibernate: Wrong column type: accountBalance, expected: numeric(19,2)?休眠:错误的列类型:accountBalance,预期:数字(19,2)?
【发布时间】:2015-12-02 13:50:31
【问题描述】:

我收到以下错误。

错误的列类型:accountBalance,预期为:numeric(19,2)。

我尝试添加columnDefinition="smallmoney"

但是没有用。

我可以将其更改为整数,但在阅读此映射后我有点谨慎..http://jtds.sourceforge.net/typemap.html

任何想法该怎么做..我在后端使用 MSSQL 服务器..

现在改成Integer

错误的列类型:accountBalance,预期:int

我现在的注解定义是这样的。

@Column(name = "AccountBalance",columnDefinition="smallmoney", nullable = false, precision = 10)
 private BigDecimal accountBalance;

【问题讨论】:

  • 数据库中的列是什么类型的?
  • smallmoney是列的数据类型
  • smallmoney 非常适合小数,但您可能会遇到问题,因为小数很容易溢出 smallmoney。我会为类使用小数,为分贝使用小数(18, 3)。

标签: java sql-server hibernate sql-server-2008


【解决方案1】:

我所做的是正确的,我得到了那个错误,因为我一直保留

hibernate.hbm2ddl.auto = validate //validate the schema, makes no changes to the database.

将此值更改为

hibernate.hbm2ddl.auto = update  // update the schema.

一切正常..

但不确定真正的原因...

【讨论】:

    猜你喜欢
    • 2015-08-02
    • 2020-09-18
    • 2017-11-26
    • 2020-11-29
    • 1970-01-01
    • 1970-01-01
    • 2020-06-17
    • 1970-01-01
    • 2012-06-04
    相关资源
    最近更新 更多