| I have been trying to get @Valid to work in a composite constraint but no luck so far. I went through HV documentation and searched online to find out if @Valid is not supported in composite constraints but I can't find any mention of that. Here is a simple example that shows the issue:
public class Foo {
@NotNull @Valid
Bar bar
@NotNullAndValid Baz baz;
}
@NotNull
@Valid
@Constraint(validatedBy={})
public @interface NotNullAndValid {
}
So my question is this: Is @Valid supported in composite constraint? If not, can you please point me to some online resource that explains why. My guess is that it's not supported for the following reason: @Valid does not support groups (i.e., if you have @Valid declared somewhere then cascade validation will always take place regardless of the validation group that was specified in/passed to the validator API call). On the other hand, composite constraints support groups/can be turned on/off by validating a bean for a specific group. If @Valid were to be placed in a composite constraint then you effectively make @Valid support groups (i.e., cascade validation will become group based rather than the mere presence/absence of @Valid constraint). Any thoughts? |