Hibernate @NotEmpty已弃用

时间:2018-02-26 10:18:06

标签: java hibernate spring-mvc

我正在使用5.2.13.Final版本的hibernate-core和 5.2.1.3 hibernate-validator的最终版本。

@NotEmpty
@Column(name = "SSO_ID", unique = true, nullable = false)
private String ssoId;
@NotEmpty为空时,如果我需要message.properties文件中的以下验证消息,则会显示

ssoId

NotEmpty.user.ssoId=SSO ID can not be blank.

@NotEmpty在最新版本中已弃用。它的等价物是什么?

2 个答案:

答案 0 :(得分:20)

通常,由于某些内容在javadoc中被标记为已弃用,因此javadoc还解释了替代内容的替代方法。

org.hibernate.validator.constraints.NotEmpty annotation javadoc州(重点是我的):

  

<强>已过时即可。使用标准javax.validation.constraints.NotEmpty 约束

请注意,由于Hibernate 5 ,Hibernate弃用了几个特定的​​验证约束类,而不赞成使用标准JSR 380-bean validation类。 另请注意,Hibernate Validator 6 库实际上是the reference implementation of this JSR

Here是Hibernate验证器弃用API的更新列表。

答案 1 :(得分:2)

使用 导入javax.validation.constraints.NotBlank; 代替 导入org.hibernate.validator.constraints.NotBlank;