Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Cecil Westerhof Newsgroups: comp.lang.java.programmer Subject: Problem with validation Date: Thu, 16 Jun 2016 08:08:13 +0200 Organization: Decebal Computing Lines: 39 Message-ID: <8760t97jjm.fsf@Equus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="12baf5125b19322b899c79c2e3878015"; logging-data="14022"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+T14Tzs63Fnc5QNK+bb+wlGZ/qR2PBT/I=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Homepage: http://www.decebal.nl/ Cancel-Lock: sha1:B55Sz4JyCb8UEjAL6eBJtu4iDqo= sha1:L0MSTO3vgK3AwFBx5+l6rQUeHHM= Xref: csiph.com comp.lang.java.programmer:34659 We have a strange problem with validation. We defined the following annotation: @Documented @Constraint(validatedBy = {}) @Target({ FIELD }) @Retention(RUNTIME) @ReportAsSingleViolation @NotNull @Size(min = 1) public @interface NotEmpty { // default final static String errorMessage = "Field is not allowed to be empty"; Class[] groups() default {}; String message() default errorMessage; Class[] payload() default {}; } We have this annotation defined on 8 fields, like: @NotEmpty(message = "ZIP-code is not allowed to be empty") Only one field (the one with the ZIP-code) is empty, but when we call persist we get a validation exception of five of them. When we print the name of the field, the message and the invalid value, we see it is the NotEmpty annotation that fired and that except for ZIP-code the fields are filled. ZIP-code contains the empty string. Also when we fill ZIP-code the persist does not fire with an validation exception. What could be the reason we get a validation exception for four fields we should not get one for? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof