When a bean property of type java.util.Set is annotated with @Valid (cascade validation), and an element of that Set is violated, the resulting Path of the ConstraintViolation does contain no information which element of the Set is violated. Unfortunately, the validation spec does not describe how the Path should be build when traversing a java.util.Set. However, using a Set is the most natural many-association type when it comes to domain modeling.
Violated elements of Lists and arrays can be identified by their index, violated elements in a Map can be identified by the key. The only way to reliably identify the violated element of a Set is the element itself. Therefore the violated element has to be stored in the Path.
Since the spec is very unclear what to do with Set elements, I suggest to store the violated element as Node.key in the Path. This would make the API changes minimal. It makes even more sense, since a Set can be considered as special kind Map, where each element is mapped to itself.
|