Search code examples
javahibernate-validator

Where is ClassValidator in Hibernate Validator?


Using hibernate-validator-4.2.0.Final.jar and the ClassValidator class is nowhere to be found inside of it. The official PDF for the 3.1.0.GA release shows it as existing inside the org.hibernate.validator package, but inside both my jar and the official repo it is not there.

This leads me to believe either:

  • it has been deprecated in lieu of something else; or
  • it has just been moved somewhere and I can't seem to find it!

If it has been deprecated then what is the best way to use the annotations and to check if something validates (or not)? If it has been deprecated, then the "old" way of doing this was to use:

ClassValidator<SomeBeanClass> validator = new ClassValidator<SomeBeanClass>();
SomeBeanClass bean = new SomeBeanClass();

// use bean

InvalidValues[] badVals = validator.getInvalidValues(bean);

And if its been moved, then where is it?!?! Thanks in advance!


Solution

  • ClassValidator is part of the 3.x version of Hibernate Validator.

    Hibernate Validator 4.x is a new development which is also the reference implementation of JSR 303 ("Bean Validation"). The equivalent class there is javax.validation.Validator.

    I recommend to have a look at the quickstart guide of the HV 4.x reference manual which gives an introduction on how to use the API.