[hibernate-dev] null values in validation

Dag Hovland hovlanddag at gmail.com
Sat Oct 16 04:54:58 EDT 2010


On 15/10/10 10:55, Hardy Ferentschik wrote:

> I added some comments to
> http://opensource.atlassian.com/projects/hibernate/browse/HV-390
> If you want to get some feedback regarding the code I suggest you attach a
> patch to the
> issue or you use the new possibilities we have now through the move to git
> (http://github.com/hibernate/hibernate-validator) by forking the validator
> repo.

Thanks. I will upload a diff hopefully tomorrow, we had some (irrelevant) practical problems :)
>
> I think the composing constraint needs still to honor things like
> @ReportAsSingleViolation.
> In case of a disjunction - if all validation fails I think you should get
> the violation
> errors for all of them (unless @ReportAsSingleViolation is used). As soon
> as one
> validation succeeds you don't get any validation error.

Ok. For disjunction ("OR") we will change it as you suggest. A larger problem is with negation,
called "ALLFALSE". ALLFALSE means that the conjunction of the negations should hold, that is, all
the composed constraints should fail. If everything leading to ALLFALSE failing should be reported,
the validator would need to keep track of all _succeeding_ constraints. (Reporting the failing
constraints when ALLFALSE fails would give exactly the messages we do not want to show.) So I
believe that for ALLFALSE, the annotation should always be treated as though it has
@ReportAsSingleViolation.

>
>> Another thing we wondered about is the default behaviour of  built-in
>> constraints when they validate null values. Are they supposed to succeed
>> on null values by default?
>
> That's a suggestion by the Bean Validation Specification.

If this is the case, we believe "@NotNull" should always be seen as a conjunction. It should, for
example, not be part of an "OR". For example:

@NotNull
@Size(min=2,max=10)
@Bool(OR)
@SomeConstraint{...}


would not really make sense, since if @NotNull fails, @Size would hold.

Regards,

Dag Hovland




More information about the hibernate-dev mailing list