如何在休眠时指定Double的精度? [英] How to specify Double's precision on hibernate?

查看:100
本文介绍了如何在休眠时指定Double的精度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从hibernate注释创建一个表。我需要有一个Double类型的列,其长度如下所示:(10,2)。
所以SQL语法如下所示:

  ... DOUBLE(10,2).... 

我试过这样做:

  @Column(length = 10,precision = 2)... 

但是当我查看我创建的表格时,没有指定Double列的长度。 hibernate是否有解决方案,或者是否需要手工修改表格配置?



谢谢!

解决方案 >仅当使用字符串值的列时,Column注释长度元素才适用。在你的情况下,你应该使用精度比例元素。

  @Column(precision = 10,scale = 2)


$ b $ 这是规范写到的内容:

/ code> - 精度 - (可选)精确度为小数(准确的
数字)列。 (仅在使用
十进制列时适用)。
  • int - scale - (可选)小数(精确数值)
    列的比例。 (仅在使用十进制
    列的情况下适用。)




  • 参考




    • JPA 1.0规范

      • 第9.1.5节列注释$ / b>


    I try to create a table from hibernate annotations. I need to have a column of Double type, with the length specified like : (10,2). So SQL syntax show like:

    ... DOUBLE(10,2) ....
    

    I have tried to do that:

    @Column(length = 10, precision = 2) ...
    

    but when i look at my created table, it is not specified the length for Double column. Does hibernate has solution for that or is it necessary to alter table configuration by hand?

    Thanks!

    解决方案

    The length element of the Column annotation applies only if a string-valued column is used. In your case, you should use the precision and the scale elements.

    @Column(precision=10, scale=2)
    

    Here is what the specification writes about them:

    • int - precision - (Optional) The precision for a decimal (exact numeric) column. (Applies only if a decimal column is used.)
    • int - scale - (Optional) The scale for a decimal (exact numeric) column. (Applies only if a decimal column is used.)

    References

    • JPA 1.0 Specification
      • Section 9.1.5 "Column Annotation"

    这篇关于如何在休眠时指定Double的精度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆