Search code examples
javahibernate-validator

Is there any way to control the order of hibernate validator doing validation?


We have a requirement that every fields of the object must be validated in a special order.

For example, we have Person object like below:

public class Person {
    @NotNull
    private String firstName;
    @NotNull
    private String lastName;

    // getter and setter
}

When I use the javax.validation.Validator to validate this object, we need to make sure that the firstName always be validated first and then lastName. Is there any way for hibernate validator archive that requirement?


Solution

  • You want to use group sequences. In particular you probably want to redefine the default group for your entity. See also Redefining the Default group for a class as defined by the Bean Validation specification .