Hibernate @NotEmpty is deprecated

只谈情不闲聊 提交于 2020-03-18 10:25:53

问题


I am using 5.2.13.Final version of hibernate-core and 5.2.13.Final version of 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.user.ssoId=SSO ID can not be blank.

But @NotEmpty is deprecated in the latest version. What is its equivalent?


回答1:


Generally, as something is marked as deprecated in a javadoc, the javadoc explains also what is the alternative to.

The org.hibernate.validator.constraints.NotEmpty annotation javadoc states (emphasis is mine) :

Deprecated. use the standard javax.validation.constraints.NotEmpty constraint instead

Note that since Hibernate 5, Hibernate deprecated several of its specific validation constraint classes in favor to standard JSR 380-bean validation classes.
Note also that the Hibernate Validator 6 library is actually the reference implementation of this JSR.

Here is an updated list of deprecated API for Hibernate validator.




回答2:


Use import javax.validation.constraints.NotBlank; instead of import org.hibernate.validator.constraints.NotBlank;



来源:https://stackoverflow.com/questions/48986091/hibernate-notempty-is-deprecated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!