It has been a couple of months since our last Hibernate Validator release and we have made some significant progress since then.

We just released Hibernate Validator 6.0.8.Final containing all these bugfixes and enhancements.

This is a recommended upgrade for everyone using Hibernate Validator 6.0.x and it is a drop-in replacement of 6.0.7.Final.

What’s new

Pass a payload to your constraint validators

Matthias Kurz worked on allowing to pass an arbitrary payload to the constraint validators.

Think of it as a good way to make your constraint validators behave differently depending on your environment (locale, production/staging environment, global objects you initialize at bootstrap and want to inject in your constraint validators…​).

The payload is an Object so it can be a String, a Map or even a proper bean.

You can define the constraint validator payload when initializing the ValidatorFactory:

ValidatorFactory validatorFactory = Validation.byProvider( HibernateValidator.class )
    .configure()
    .constraintValidatorPayload( "US" )
    .buildValidatorFactory();

Validator validator = validatorFactory.getValidator();

and also refine it when initializing a specific Validator:

HibernateValidatorFactory hibernateValidatorFactory = Validation.byDefaultProvider()
    .configure()
    .buildValidatorFactory()
    .unwrap( HibernateValidatorFactory.class );

Validator validator = hibernateValidatorFactory.usingContext()
    .constraintValidatorPayload( "FR" )
    .getValidator();

Your constraint validator can obtain the constraint validator payload in its initialize() method:

public class ZipCodeValidator implements HibernateConstraintValidator<ZipCode, String> {

    public String countryCode;

    @Override
    public void initialize(ConstraintDescriptor<ZipCode> constraintDescriptor,
            HibernateConstraintValidatorInitializationContext initializationContext) {
        this.countryCode = initializationContext
                .getConstraintValidatorPayload( String.class );
    }

    [...]
}

You can find all the information related to this new feature in our reference documentation.

Performance and build improvements

Marko worked on a few performance improvements (HV-1566, HV-1543 and HV-1444) that should make Hibernate Validator 6.0.8.Final faster than ever.

HV-1444 also improved our correctness towards the Bean Validation specification in some corner cases related to container element constraints.

We also made quite a lot of build improvements related to JDK 9 and the TCK and upgraded our dependencies.

WildFly 12

As WildFly 12 got released recently, we updated our build to test Hibernate Validator on WildFly 11 and 12.

We currently produce WildFly patches to upgrade the Hibernate Validator modules inside WildFly for these two versions.

Note that WildFly 12 now includes Bean Validation 2.0 and Hibernate Validator 6.0 (6.0.7.Final) but they are not enabled by default. You need to enable the EE8 preview mode by appending the ee8.preview.mode option, as explained in the WildFly 12 announcement.

Bugs fixed

We also fixed a few bugs, most notably:

  • HV-1461 - A bug that could interfere with method overriding in a few corner cases - it was fixed by a Classmate upgrade

  • HV-1551 - It wasn’t possible to define @Size constraints on raw collections (e.g. private List myList)

Translation updates

The Spanish translation of the default messages was updated by Hillmer Chona.

Full changelog

The complete list of fixed issues can be found on our JIRA.

Getting 6.0.8.Final

To get the release with Maven, Gradle etc. use the GAV coordinates org.hibernate.validator:{hibernate-validator|hibernate-validator-cdi|hibernate-validator-annotation-processor}:6.0.8.Final. Note that the group id has changed from org.hibernate (Hibernate Validator 5 and earlier) to org.hibernate.validator (from Hibernate Validator 6 onwards).

Alternatively, a distribution bundle containing all the bits is provided on SourceForge (TAR.GZ, ZIP).

If you want to benefit from the new features of this version on WildFly, we also provide WildFly patches for WildFly 11 and WildFly 12. You can read about how to apply such patches here.

What’s next?

We will continue to publish maintenance releases to fix quickly the issues reported by our users.

We updated our roadmap with the ideas we have for the future. If you want to join us, don’t hesitate to pick a task and come discuss it with us.

Feedback, issues, ideas?

To get in touch, use the usual channels:


Back to top