I’m validating a user password using an @Pattern regex.
That works fine, but then I hash the password, which results in a password of much more than the 16 characters my validation has specified.
However this validation rule is filtering down to my JPA layer, so my hashed password is far too long for the validation rule, and I get a ‘Validation failed for….’ message when I try to persist my object.
Sure I’m missing something fundamental, but what is it?
Thanks
That’s a typical scenario, and the solutions are two:
@TransientfieldrepeatPasswordand place the validation there, rather than on the one that gets persisted in the DB.In short – you shouldn’t have the annotation on your actual password field of the entity. Turning off validation for the persistence layer is an option, but is not preferred as it may lead to a lot of side-effects.