Java 不推荐使用休眠@NotEmpty
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48986091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hibernate @NotEmpty is deprecated
提问by Brijesh Soni
I am using 5.2.13.Finalversion of hibernate-coreand 5.2.13.Final version of hibernate-validator.
我正在使用5.2.13.Final版本的hibernate-core和 5.2.13.Final 版本的hibernate-validator。
@NotEmpty
@Column(name = "SSO_ID", unique = true, nullable = false)
private String ssoId;
@NotEmpty
comes in picture when I need the following validation message from themessage.properties
file when ssoId
is empty:
@NotEmpty
当我需要message.properties
文件中的以下验证消息时,该文件ssoId
为空时出现:
NotEmpty.user.ssoId=SSO ID can not be blank.
NotEmpty.user.ssoId=SSO ID can not be blank.
But @NotEmpty
is deprecated in the latest version. What is its equivalent?
但@NotEmpty
在最新版本中已弃用。它的等价物是什么?
采纳答案by davidxxx
Generally, as something is marked as deprecated in a javadoc, the javadoc explains also what is the alternative to.
通常,由于某些内容在 javadoc 中被标记为已弃用,因此 javadoc 还解释了替代方法。
The org.hibernate.validator.constraints.NotEmpty annotation javadocstates (emphasis is mine) :
该org.hibernate.validator.constraints.NotEmpty注释的javadoc国家(重点是我的):
Deprecated. use the standard javax.validation.constraints.NotEmptyconstraint instead
已弃用。改用标准 javax.validation.constraints.NotEmpty约束
Note that since Hibernate 5, Hibernate deprecated several of its specific validation constraint classes in favor to standard JSR 380-bean validationclasses.
Note also that the Hibernate Validator 6library is actually the reference implementation of this JSR.
请注意,从 Hibernate 5 开始,Hibernate 弃用了几个特定的验证约束类,转而使用标准的JSR 380-bean 验证类。
另请注意,Hibernate Validator 6库实际上是此 JSR 的参考实现。
Hereis an updated list of deprecated API for Hibernate validator.
这是 Hibernate 验证器的已弃用 API 的更新列表。
回答by user3129211
Use import javax.validation.constraints.NotBlank;instead of import org.hibernate.validator.constraints.NotBlank;
使用 import javax.validation.constraints.NotBlank; 而不是导入 org.hibernate.validator.constraints.NotBlank;