@Max在长包装类型上不接受10位数字

时间:2017-08-04 13:19:20

标签: java hibernate bean-validation

作为实体定义的一部分,@ Max(javax.validation.constraints.Max)不会使用较高的值来验证10位整数

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

Eclipse在第二行浮动一个红色标记,并带有消息The value for annotation attribute Max.value must be a constant expression

我查看了MAX_VALUE Integer只发现2147483647也是10位数。

注意: hibernate-core:5.0.12validation-api:2.0.0.CR3

我将类型修改为长包装器

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

但是,错误仍然是顽固的。

1 个答案:

答案 0 :(得分:1)

@Max的参数定义为long。例如,将其设置为42表示传递int42,该值会转换为long42L然后设置。标准操作程序,真的。这里没有关于@Max的特别之处。

当您通过9999999999时,它会尝试将其解释为int并失败。 Eclipse正在警告你这一点,也许并不是非常清楚。要传入9999999999,您需要将其设为long,这意味着将约束指定为@Max(9999999999L)

相关问题