-->
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: Problems with using hibernate validator
PostPosted: Wed Apr 14, 2010 5:41 pm 
Newbie

Joined: Tue Oct 20, 2009 4:53 pm
Posts: 4
Location: Sofia, Bulgaria
Hello,

I'm using the bean validation API and its implementation provided by Hibernate validator for the first time.

I've setup my project using maven. I've put the following dependencies amongst others:

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>3.1.0.GA</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>

Then I annotated one of my classes with the JSR 303 annotations, created an instance of it and tried to validate it. But the following method failed:

Code:
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();


The exact exception is:

Code:
javax.validation.ValidationException: Unable to find a default provider
   at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:264)
   at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:111)


After reading some forums I understood that a JSR 303 implementation should be in my classpath. I have it - hibernate-validator. Next I did some debugging and found that my hibernate-validator jar is missing META-INF/services/javax.validation.spi.ValidationProvider file and thus the validator resolver cannot find which is the exact implementation to instantiate.

Could you help me with this? It seems that it's only me in the whole internet, that has this problem, so apparently I'm doing something wrong. :-)

Thanks,
Ivan


Top
 Profile  
 
 Post subject: Re: Problems with using hibernate validator
PostPosted: Thu Apr 15, 2010 5:16 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hello,
hibernate-validator 3.1 is the precursor of the standard, to use the new javax.validation API you need to use version 4:
Code:
<dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-validator</artifactId>
   <version>4.0.2.GA</version>
</dependency>
<dependency>
   <groupId>javax.validation</groupId>
   <artifactId>validation-api</artifactId>
   <version>1.0.0.GA</version>
</dependency>

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Problems with using hibernate validator
PostPosted: Fri Apr 16, 2010 9:48 am 
Newbie

Joined: Tue Oct 20, 2009 4:53 pm
Posts: 4
Location: Sofia, Bulgaria
Hello s.grinovero,

Thank you very much. I changed the hibernate-validator version and it worked well.

Funny enough, I'm using the m2eclipse plugin, which provides something like code completion for most of the dependency attributes, including the version. So, according to my eclipse distribution, the latest version was 3.1.0, that is why I chose that.

Anyway, thanks for the quick and correct reply!

BTW, I did not have to specify the javax.validation dependency explicitly. Probably hibernate-validator has it in its pom.xml.

Regards,
Ivan


Top
 Profile  
 
 Post subject: Re: Problems with using hibernate validator
PostPosted: Fri Apr 16, 2010 10:52 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
just remember the m2eclipse plugin is indexing only the artifacts you have used before, or for which it was able to download a compressed index. Most repositories don't provide such an index, so your local index will not reveal new release until you use them explicitly..

_________________
Sanne
http://in.relation.to/


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.