Hibernate Validator 4.2.0.Beta2 is bottled up and ready for consumption via the JBoss Maven Repository or SourceForge.

Since Beta1 we have been focusing on method level validation details and bug fixes. One important issue in this regard is HV-421 which defines the behavior of parameter constraint validation. Generally a logical AND is used to combine all constraints defined within a class hierarchy on a given field or method. Doing the same for method parameter constraints, however, causes ambiguities with the definition of Programming by contract where subtypes may only weaken preconditions defined by supertypes. In order to support this one would have to combine all parameter constraints within a hierarchy using an OR. A conservative alternative (the one we chose for this release) is to prohibit multiple parameter constraints on the same parameter within a class hierarchy. HV-421 discusses in more detail. We are very interested in feedback on this.

Another method level validation related feature is the extension of the meta data API (HV-440). We introduced three more interfaces TypeDescriptor, MethodDescriptor and ParameterDescriptor which you can all find in the org.hibernate.validator.method.metadata package. Here is an usage example:

 MethodValidator validator = Validation.byProvider( HibernateValidator.class )
    .configure()
    .buildValidatorFactory()
    .getValidator()
    .unwrap( MethodValidator.class );

TypeDescriptor typeDescriptor = validator.getConstraintsForType( clazz );
...
Set<MethodDescriptor> constrainedMethods = descriptor.getConstrainedMethods();
...
List<ParameterDescriptor> parameterConstraints = methodDescriptor.getParameterConstraints();
ParameterDescriptor parameterDescriptor = parameterConstraints.get( 0 );
assertTrue( parameterDescriptor.hasConstraints() );
...
Note: MethodValidator.validateParameters was renamed into MethodValidator.validateAllParameters (HV-415).

To mention at least one method level validation unrelated feature - Hibernate Validator has now a fail fast option. When enabled, validation will terminate on the first validation error. This could be interesting for large object graph validation. You can enable the fail fast flag for example via:

ValidatorFactory factory = Validation.byProvider( HibernateValidator.class )
                             .configure()
                             .failFast( true )
                             .buildValidatorFactory();
You find the full change log for this release here. Please provide feedback via the Validator Forum and the Jira issue tracker.

Enjoy!

P.S. For all the Seam people out there. Gunnar started a new Seam 3 module called SeamValidation which offers amongst other a CDI extension for method level validation. Check it out!

P.P.S. Make sure to also provide feedback on what we should include into Bean Validation 1.1


Back to top