How to specify Double's precision on hibernate?

后端 未结 4 698
温柔的废话
温柔的废话 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:15

    You can also use @Digits from the hibernate validator API which implements the javax.validation Bean Validation standard

    @Digits(integer = 10 /*precision*/, fraction = 2 /*scale*/)
    

    From the Javadocs

    The annotated element must be a number within accepted range Supported types are:

    • BigDecimal
    • BigInteger
    • CharSequence
    • BigInteger
    • byte, short, int, long, and their respective wrapper types

    null elements are considered valid

提交回复
热议问题