Hi,
We integrated the validation framework (
hibernate-validator-4.0.2.GA.jar) in our framework and now you can create constraints on the runtime and validate other items also on runtime. To do so we wrapped the (JSR303 and other) constraints in our item and when reloading the validation framework we inject them as xml InputStream.
Code:
Validator validator;
Configuration<?> config = Validation.byDefaultProvider().configure();
InputStream input = constraintsExtractor.extractConstraints(); //converts the constraints wrapper items into the xml fragments
config.addMapping(input);
IOUtils.closeQuietly(input);
validator = config.buildValidatorFactory().getValidator();
This works perfectly fine.
The Problem now is, you can define "invalid" constraints like setting the JSR303 Past constraint to a boolean attribute. This is loaded into the framework without any errors.
But only when instances of the items are validatet the framework detects the illegal constraint
Code:
javax.validation.UnexpectedTypeException: No validator could be found for type: java.util.Date
at org.hibernate.validator.engine.ConstraintTree.verifyResolveWasUnique(ConstraintTree.java:236)
at org.hibernate.validator.engine.ConstraintTree.findMatchingValidatorClass(ConstraintTree.java:219)
at org.hibernate.validator.engine.ConstraintTree.getInitializedValidator(ConstraintTree.java:167)
at org.hibernate.validator.engine.ConstraintTree.validateConstraints(ConstraintTree.java:113)
at org.hibernate.validator.metadata.MetaConstraint.validateConstraint(MetaConstraint.java:121)
at org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:334)
at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForRedefinedDefaultGroup(ValidatorImpl.java:278)
at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:260)
at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:213)
at org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:119)
at de.hybris.platform.validation.services.impl.DefaultValidationService.validate(DefaultValidationService.java:165) //our class here
Now my question:
Is there any way to check if the constrains are valid constraints? The given methods in the stacktrace are mostly private.
regards
Marcel