JPA @Size annotation for BigDecimal

浪尽此生 提交于 2019-12-03 05:40:38

You could use the Hibernate Validator directly, and annotate your field with @Digits like so:

@Digits(integer=5, fraction=2)
@Column(name = "weight")
private BigDecimal weight;
borjab

See this answer

@Column(nullable= false, precision=7, scale=2)    // Creates the database field with this size.
@Digits(integer=9, fraction=2)                    // Validates data when used as a form
private BigDecimal myField;
@Column(columnDefinition = "DECIMAL(7,2)")

If you're asking how you should validate, you should use the @Min and @Max annotations or the @DecimalMin and @DecimalMax annotations.

@Size is an annotation used to validate a property, not to define its column. @Size is typically used to assure that a string or a collection is of a certain size.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!