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?
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.
@NotEmpty: a constrained CharSequence, Collection, Map, or Array is valid as long as it's not null, and its size/length is greater than zero. @NotBlank: a constrained String is valid as long as it's not null, and the trimmed length is greater than zero.
notEmpty() is a static method of the Validate class that is used to check whether the given argument array/map/collection/character sequence is not null or empty. If the array/map/collection/character sequence is either null or empty, the method throws an exception.
notBlank() is a static method of the Validate class that is used to check that the specified argument character sequence is not null , a length of zero, empty, or whitespace. Otherwise, the method throws an exception with the specified message.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With