Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate @NotEmpty annotation equivalent in Javax.package or alternative

Is there a way to implement @NotEmpty hibernate validation without writing custom validation? javax.validation package does not contain this annotation. Only @NotNull. But it does not validate for Non-null but empty values. So I would like to see an alternative for @NotEmpty.

Using @Pattern? How?

like image 960
Kevin Rave Avatar asked Jul 05 '13 05:07

Kevin Rave


People also ask

What is the difference between @NotNull and @NotEmpty and NotBlank?

@NotNull : The CharSequence, Collection, Map or Array object is not null, but can be empty. @NotEmpty : The CharSequence, Collection, Map or Array object is not null and size > 0. @NotBlank : The string is not null and the trimmed length is greater than zero.

Is @NotBlank deprecated?

Annotation Type NotBlankDeprecated. Validate that the annotated string is not null or empty. The difference to NotEmpty is that trailing whitespaces are getting ignored.

What is @NotNull in Java?

@NotNull The @NotNull annotation is, actually, an explicit contract declaring that: A method should not return null. Variables (fields, local variables, and parameters) cannot hold a null value.

What is javax validation?

Simply put, Javax validation works with two main group of annotations. Annotations to ensure that validation happens like @Valid or @Validated. Annotations to denote the kind of constraints to be enforced on a value like @NotNull, @Pattern.


1 Answers

NotEmpty is just a combination of @NotNull and @Size(min=1).

like image 105
Affe Avatar answered Oct 11 '22 05:10

Affe