Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA2: @Min constraint for float

Tags:

java

jpa

entity

Is it possible to apply @Min constraint to a float type?

For example:

@Entity
public class Stock
{
    @Id
    @GeneratedValue
    private Long id;

    @NotNull
    @Min(0.1)
    private float count;
}

Long type is required in @Min annotation so is there any other way how to achieve the same?

like image 581
Martin Nuc Avatar asked Dec 20 '22 23:12

Martin Nuc


1 Answers

@DecimalMax

The value of the field or property must be a decimal value lower than or equal to the number in the value element.

@DecimalMax("30.00")
BigDecimal discount;

@DecimalMin

The value of the field or property must be a decimal value greater than or equal to the number in the value element.

@DecimalMin("5.00")
BigDecimal discount;

@Digits

The value of the field or property must be a number within a specified range. The integer element specifies the maximum integral digits for the number, and the fraction element specifies the maximum fractional digits for the number.

@Digits(integer=6, fraction=2)
BigDecimal
like image 90
Prabhakaran Ramaswamy Avatar answered Jan 02 '23 10:01

Prabhakaran Ramaswamy