[hibernate-dev] Fail fast feature for Hibernate Validator
Gunnar Morling
gunnar.morling at googlemail.com
Thu Oct 7 18:06:38 EDT 2010
2010/10/6 Emmanuel Bernard <emmanuel at hibernate.org>
>
> Too sad, that javax.validation.ValidatorContext is not defined as
>
> public interface ValidatorContext <V extends ValidatorContext<V>> {
>
> }
>
> If it were, we wouldn't need a dedicated method
> HibernateValidatorFactory#usingHibernateContext(), but
> HibernateValidatorFactory could be defined as
>
> public interface HibernateValidatorFactory extends ValidatorFactory {
>
> HibernateValidatorContext usingContext();
>
> }
>
> then, allowing the validator to be retrieved like that:
>
> failFastValidator =
> factory.unwrap(HibernateValidatorFactory.class)
> .usingContext()
> .maxConstraintViolationCount(5)
> .getValidator();
>
>
> Yes I've hesitated back in the days and thought unwrap was enough :(
> I wonder if we can retroactively enhance it without breaking clients.
>
>
I'm not totally sure. I tried it out and a quick look didn't show any real
problems. People assigning the ValidatorContext to a variable would get a
"raw type" warning. Per se that's no problem, plus I think hardly anybody
would do that anyway as there simply is no need store the context when
building a validator.
More information about the hibernate-dev
mailing list