javax.validation.ConstraintViolationException: validation failed for classes [*] during update time for groups [javax.validation.groups.Default, ]

This message wasted many hours to figure out the solution.

javax.validation.ConstraintViolationException: validation failed for classes [*] during update time for groups [javax.validation.groups.Default, ]

When I applied the validation as following, I found that the confirmPassword is the field causing validation error.

ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
        Validator validator = factory.getValidator();
       
        Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);

        System.out.println("constraintViolations.size : "+constraintViolations.size());
        Iterator<ConstraintViolation<User>> iterator = constraintViolations.iterator();
        while (iterator.hasNext()) {
            ConstraintViolation<dpgsource.users.User> constraintViolation = (ConstraintViolation<dpgsource.users.User>) iterator
                    .next();
            System.out.println(constraintViolation.getMessage()+", "+constraintViolation.getInvalidValue()+", "+constraintViolation.getPropertyPath());
        }


No comments:

Popular Posts