JPA @Size annotation for BigDecimal

ThreaT picture ThreaT · Jan 3, 2014 · Viewed 38.4k times · Source

How do I use the @Size annotation for MySQL DECIMAL(x,y) columns?

I'm using BigDecimal, but when I try to include the @Size max it doesn't work. Here is my code:

@Size(max = 7,2)
@Column(name = "weight")
private BigDecimal weight;

Answer

mavroprovato picture mavroprovato · Jan 3, 2014

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;