Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Can't find bean validation provider in karaf
PostPosted: Fri Jun 02, 2017 10:35 pm 
Regular
Regular

Joined: Mon Aug 07, 2006 6:22 pm
Posts: 64
I've implemented some code using javax.validation and Hibernate Validator. The unit tests are working fine. The build produces OSGi bundles and features, and runs in Karaf.

When I run my PaxExam integration test, I get "Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath." As far as I can tell, I AM adding it to my classpath. I have a features.xml file that I've been incrementally adding dependencies to. It finally got past Karaf bundle resolution, but now it's failing with an exception with this message:

"Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath."

I would include the stacktrace, but it doesn't look useful to me. Most of it is in my code, junit, and paxexam.

I'm attempting to use version 5.4.1.Final of HV. Note again that the unit tests doing validation are working fine. It took a while to get the dependencies correct to get that far (like using version "3.0.1-b08" of "javax.el".

I've seen some mentions of a "hibernate-validator-osgi-karaf-features" artifact, but I'm not sure if that's relevant. I'm attempting to use both the hibernate-validator artifact and the hibernate-validator-annotation-processor artifact.


Top
 Profile  
 
 Post subject: Re: Can't find bean validation provider in karaf
PostPosted: Mon Jun 05, 2017 8:31 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2534
Location: Third rock from the Sun
Hi,

have a look here:
- https://github.com/hibernate/hibernate- ... rationtest

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


Top
 Profile  
 
 Post subject: Re: Can't find bean validation provider in karaf
PostPosted: Mon Jun 05, 2017 11:42 am 
Regular
Regular

Joined: Mon Aug 07, 2006 6:22 pm
Posts: 64
Thanks for the reply, but I need more information. I might be able to get the integration test you refer to working, but I have to integrate the required references into my pom and features files.

When I just put the reference to the "hibernate-validator-osgi-karaf-features" artifact into my features.xml file, it failed with:
Code:
Could not find artifact org.hibernate:hibernate-validator-osgi-karaf-features:jar:5.4.1.Final in central (http://repo1.maven.org/maven2/)


But I guess that shouldn't be that surprising, as that artifact is a POM artifact, not a JAR artifact. Is there some way to reference a POM artifact in a features.xml file?

Here is my current features.xml file excerpt:
Code:
        <bundle start-level="100">wrap:mvn:javax.validation/validation-api/1.1.0.Final$Bundle-Name=javax.validation&amp;Bundle-SymbolicName=javax.validation&amp;Bundle-Version=1.1.0.Final</bundle>
        <bundle>mvn:org.hibernate/hibernate-validator/5.4.1.Final</bundle>
        <bundle>wrap:mvn:org.hibernate/hibernate-validator-osgi-karaf-features/5.4.1.Final$Bundle-Name=hibernate-validator-osgi-karaf-features&amp;Bundle-SymbolicName=hibernate-validator-osgi-karaf-features&amp;Bundle-Version=5.4.1.Final</bundle>


Top
 Profile  
 
 Post subject: Re: Can't find bean validation provider in karaf
PostPosted: Mon Jun 05, 2017 12:10 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2534
Location: Third rock from the Sun
The "hibernate-validator-osgi-karaf-features" artifact is just an example features file which we use to run integration tests.

So since it's an example we don't publish it to Maven central, and I don't think you should reuse our example as-is but you probably want to look at it and compare it with your own features file:

https://raw.githubusercontent.com/hiber ... atures.xml

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


Top
 Profile  
 
 Post subject: Re: Can't find bean validation provider in karaf
PostPosted: Mon Jun 05, 2017 3:40 pm 
Regular
Regular

Joined: Mon Aug 07, 2006 6:22 pm
Posts: 64
I've made progress in correctly referencing features, but I'm effectively back to the original problem. I finally figured out that I need to just reference the "hibernate-validator" feature from the "hibernate-validator-osgi-karaf-features" artifact, but the result is the same. It stills says it can't find HV in the classpath.

I tried changing the "LogLevel" in my PaxExam configuration from WARNING to DEBUG. This gives me a lot more information, but perhaps not very useful. Is there some way I could set debug levels that might help explain why it can't find HV in the classpath?


Top
 Profile  
 
 Post subject: Re: Can't find bean validation provider in karaf
PostPosted: Tue Jun 06, 2017 5:30 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 382
The problem likely is that the code in the Bean Validation API JAR cannot find the service provider implementation (ValidationProvider) in the HV JAR. So you need to specify a custom provider resolver for that in OSGi:

Code:
public class OsgiServiceDiscoverer implements ValidationProviderResolver {

    @Override
    public List<ValidationProvider<?>> getValidationProviders() {
        return Collections.<ValidationProvider<?>>singletonList( new HibernateValidator() );
    }
}


Code:
ValidatorFactory validatorFactory = Validation.byDefaultProvider()
        .providerResolver( new OsgiServiceDiscoverer() )
        .configure()
        .buildValidatorFactory();
Validator validator = validatorFactory.getValidator();

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 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.