-->
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.  [ 3 posts ] 
Author Message
 Post subject: Reusing HibernateValidatorConfiguration
PostPosted: Sat Mar 17, 2012 1:43 pm 
Newbie

Joined: Sat Mar 17, 2012 1:33 pm
Posts: 7
Is HibernateValidatorConfiguration meant to be reusable? Before I realized that org.hibernate.validator.engine.ValidatorImpl implemented both Validator and MethodValidator, I tried to do this:

Code:
      HibernateValidatorConfiguration config = Validation.byProvider(HibernateValidator.class).configure();
      Validator validator = config.buildValidatorFactory().getValidator();
      MethodValidator methodValidator = config.buildValidatorFactory().getValidator().unwrap(MethodValidator.class); // Yeah, it doesn't make much sense to do this, does it, but anyway ...


and I got a NPE because ConfigurationImpl.buildValidatorFactory() resets validationBootstrapParameters, losing the previous value of validationBootstrapParameters.getProvider().

Just wondering.

-Ron


Top
 Profile  
 
 Post subject: Re: Reusing HibernateValidatorConfiguration
PostPosted: Sun Mar 18, 2012 6:14 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi Ron,

That's a good question. I had a quick look at the spec and the API documentation of javax.validation.Configuration, and it seems to me that this ist currently not clearly specified. I posted the question to the BV EG mailing list, let's see what the other folks think. Personally I think it might make sense to allow such a usage, at least we have to make clear whether it's allowed or not.

For your specific example you just should unwrap the validator instance as you said, as otherwise the constraint meta-model would be instantiated twice in the two factories.

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: Reusing HibernateValidatorConfiguration
PostPosted: Tue Mar 20, 2012 12:12 am 
Newbie

Joined: Sat Mar 17, 2012 1:33 pm
Posts: 7
Thanks, Gunnar. Wow, you're faster than I am on the mailing lists. ;)

-Ron


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.