Ok, so we want to allow users to do a manual migration. To do this a model object has to be in a certain state. I do not want to validate every instance of this class or really any instance of this class automatically. I know how to call the validator manually (as a general thing) but what I'm wondering is can I execute the validator without having those annotations on the model? I'd simply like to execute a arbitrary validation code agains the model. The reason for wanting to use the validation api is because it collects constraint violations.
e.g something like this
class ValidForMigration implements ConstraintViolation<MyModel> {
boolean isValid( MyModel model ) {
if ( model.getFoo() == null ) { return false; }
return true;
}
}
MySvc {
...
void doMigrate(... ) {
validator.validate( myModel, new ValidForMigration() )
}
}
Bean Validation is based on the principle of declarative constraints, i.e. constraints are declared once - using annotations, XML descriptors or (in Hibernate Validator) an API - and then validated as needed at suitable points in the object lifecycle. So what you describe is not directly possible in Bean Validation.
The Hibernate Validator constraint mapping API may still be helpful to you, though. You'd declare the constraints you want to apply during your migration using the API and set up a validator using these constraint mappings.