作为实体定义的一部分,@ 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.12
,validation-api:2.0.0.CR3
我将类型修改为长包装器
@Min(0)
@Max(9999999999)
@Column(name = "some_column", nullable = false,
columnDefinition = "INT(10) NOT NULL")
private Long someColumn;
但是,错误仍然是顽固的。
答案 0 :(得分:1)
@Max
的参数定义为long
。例如,将其设置为42
表示传递int
值42
,该值会转换为long
值42L
然后设置。标准操作程序,真的。这里没有关于@Max
的特别之处。
当您通过9999999999
时,它会尝试将其解释为int
并失败。 Eclipse正在警告你这一点,也许并不是非常清楚。要传入9999999999
,您需要将其设为long
,这意味着将约束指定为@Max(9999999999L)
。