Hibernate Validator Migration Guide

Version 4



    This section describes changes made in different release of version 4.2.0. It helps you to migrate from version 4.1.0.Final to 4.2.0.Final.




    This release do not introduce modifications which can break your existing code if you have already migrated to version 4.2.0.CR1. If you migrate from version 4.1.0.Final the following sections gives you the changes introduced during the different release leading to this Final version.




    • Hibernate Validator allows the configuration of constraints programmatically. The main feature of this release is to add the programmatic API to configure constraints on method (HV-431). To implement this in an unambiguous way we had to make yet some more changes to the programmatic API. Programmatic API looks like this now:


    {code}ConstraintMapping mapping = new ConstraintMapping();

    mapping.type( Car.class )

        .property( "manufacturer", FIELD )

            .constraint( new NotNullDef() )

        .property( "licensePlate", FIELD )

            .constraint( new NotNullDef() )

            .constraint( new SizeDef()

                .min( 2 )

                .max( 14 ) )

        .property( "seatCount", FIELD )

            .constraint( new MinDef()

                .value ( 2 ) )

    .type( RentalCar.class )

        .property( "rentalStation", METHOD )

            .constraint( new NotNullDef() ); {code}


    • Another minor modification which can impact your existing code if you migrate from Beta2 version is HV-488. If you deal with method meta data API the previous method of MethodDescriptor named getParameterConstraints() was renamed to getParameterDescriptors() to avoid confusion.



    The version Beta1 have introduced the possibility to specify constraints on Method. If you use this functionality the following changes can impact your code.


    • The method allowing to validate all parameters of a method (MethodValidor#validateParameters()) was renamed to  MethodValidor#validateAllParameters().






    • BVTCK-12 resp. HV-395 required a change in the javax.validation.Path implementation. Unless you iterate over the Path instance returned by Constraint.getPropertyPath() you are not affected by this change.
    • Programmtic configured generic constraints are now configured like this:
      {code}mapping.type( Foo.class )
      .property( "bar", FIELD )
      .genericConstraint( MyConstraint.class ).param( "value", 1 );{code}
    • When creating own subclasses of ConstraintDef is it not necessary anymore to repeat the definitions of message, payload and groups. ConstraintDef uses now self-referential generic types.