How to specify Double's precision on hibernate?

后端 未结 4 686
温柔的废话
温柔的废话 2020-12-08 03:01

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:



        
4条回答
  •  时光说笑
    2020-12-08 03:21

    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"

提交回复
热议问题