It seems that the Hibernate NotEmpty annotation NotEmpty not produce an error for lines filled with spaces ( " " ). Only works for zeros or empty strings (i.e.: new String() ). Is there a workaround / fix for this?
NotEmpty
" "
new String()
Replace @NotEmpty with the @Pattern annotation, which includes a regex expression that will tolerate strings that are pure spaces or empty (you can include both @NotEmpty and @Pattern and thus simplify the regular expression). Or write a special validator as described here .
@NotEmpty is used to check size, not content, and applies to collections as well as strings. The functionality you are looking for is provided in @NotBlank, which is string specific and ignores trailing spaces.
@NotBlank is a way to check the length of lines with an implicit trim call.
@NotBlank