-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Validation of the constraints itself before validation
PostPosted: Tue Aug 24, 2010 4:47 am 
Newbie

Joined: Tue Aug 24, 2010 3:56 am
Posts: 8
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


Top
 Profile  
 
 Post subject: Re: Validation of the constraints itself before validation
PostPosted: Wed Aug 25, 2010 4:35 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

I am not quite following what your framework does, but here are some thoughts. I hope they are helpful.

First of all the ConstraintValidator resolution algorithm is a dynamic process which occurs during each validation. The rules behind it are defined the the Bean Validation specification section 3.5.3 "ConstraintValidator resolution algorithm".

The ConstraintDescriptor class offers the method getConstraintValidatorClasses(). This method gives you all ConstraintValidators defined for a given constraint. You basically would have to get the list of ConstraintValidators and check whether there is a matching validator for the type of the member you placed the constraint on. As you mentioned Hibernate Validator does not expose any public methods you could call here.

Hibernate Validator offers, however, an annotation processor which you can use within your IDE to detect invalid placement of constraints. Unfortunately, it works so far only with annotations and does not consider xml configuration. Given your vague explanation of your framework I am not even sure whether it would help if xml would be taken into account.

--Hardy


Top
 Profile  
 
 Post subject: Re: Validation of the constraints itself before validation
PostPosted: Mon Aug 30, 2010 10:05 am 
Newbie

Joined: Tue Aug 24, 2010 3:56 am
Posts: 8
Hi, thanks for your answer.
I'll have a look into the annotation processor if we can invoke this one somehow.

Another question: is it planned to validate the xml files/streams in the near future?


Top
 Profile  
 
 Post subject: Re: Validation of the constraints itself before validation
PostPosted: Sat Sep 04, 2010 3:15 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
I guess that falls under HV-308. Hopefully part of the next release.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.