0

As part of entity definition, @Max(javax.validation.constraints.Max) won't take upper value to validate a 10 digit integer

@Min(0)
@Max(9999999999)
@Column(name = "some_column", nullable = false,
    columnDefinition = "INT(10) NOT NULL")
private Integer someColumn;

Eclipse floats a red-mark at 2nd line with a message The value for annotation attribute Max.value must be a constant expression.

I looked through to find the MAX_VALUEfor Integer only to find it as 2147483647 which is 10 digit as well.

NOTE: hibernate-core:5.0.12, validation-api:2.0.0.CR3

I modified the type to long wrapper

@Min(0)
@Max(9999999999)
@Column(name = "some_column", nullable = false,
    columnDefinition = "INT(10) NOT NULL")
private Long someColumn;

But, still the error is being stubborn.

Neil Stockton
  • 11,383
  • 3
  • 34
  • 29
soufrk
  • 825
  • 1
  • 10
  • 24

1 Answers1

3

The parameter to @Max is defined as a long. Setting it to, for example, 42 means passing the int value 42, which gets cast to the long value 42L and then set. Standard operating procedure, really. Nothing special about @Max going on here.

When you pass 9999999999 it tries to interpret it as an int and fails. Eclipse is warning you of this, just perhaps not terribly clearly. To pass in 9999999999 you need to do it as a long which means designating the constraint as @Max(9999999999L).

dcsohl
  • 7,186
  • 1
  • 26
  • 44