Hibernate - Error activating Bean Validation integration
Asked Answered
T

2

8

I am trying to set up Hibernate. But when i try to create my Session Factory, with this code:

Configuration configuration = new Configuration();
configuration.configure();
serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();        
sessionFactory = configuration.buildSessionFactory(serviceRegistry);

I get the error:

org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration
        at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:156)
        at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:303)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1760)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
    Caused by: java.lang.NoSuchMethodError: javax.validation.spi.ConfigurationState.getParameterNameProvider()Ljavax/validation/ParameterNameProvider;
        at org.hibernate.validator.internal.engine.ValidatorFactoryImpl.<init>(ValidatorFactoryImpl.java:113)
        at org.hibernate.validator.HibernateValidator.buildValidatorFactory(HibernateValidator.java:45)
        at org.hibernate.validator.internal.engine.ConfigurationImpl.buildValidatorFactory(ConfigurationImpl.java:217)
        at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:111)
        at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:445)
        at org.hibernate.cfg.beanvalidation.TypeSafeActivator.activate(TypeSafeActivator.java:96)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:150)
        ... 31 more

I have the hibernate-validator and the bean validator in my class-path (see screenshot) enter image description here

What could be the issues here?

Edit I had two additional validation-api on the classpath, but excluded them. Could they be a problem somehow. Maybe the scope=provided?

<dependency>
    <groupId>com.google.gwt</groupId>
    <artifactId>gwt-user</artifactId>
    <version>${gwtVersion}</version>
    <scope>provided</scope>
    <exclusions>
        <exclusion>
            <artifactId>validation-api</artifactId>
            <groupId>javax.validation</groupId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>com.google.web.bindery</groupId>
    <artifactId>requestfactory-server</artifactId>
    <version>2.5.1</version>
    <exclusions>
        <exclusion>
            <artifactId>validation-api</artifactId>
            <groupId>javax.validation</groupId>
        </exclusion>
    </exclusions>
</dependency>

Edit 2

Solved the problem: I had yet another bean validator jar in the class path. But not from maven, so i didn't realize it. Removing that solved the problem. Thanks a lot for the hints!

Tankersley answered 23/6, 2013 at 23:38 Comment(5)
By the NoSuchMethodError, I would investigate issues with the versions of libraries/jvm (that you are using a library so old that it does not provide the expected method).Letrice
... tough the versions shown in the classpath should match (1.1.0 is the last release library)Letrice
Are you sure you don't have a BeanValidation 1.0 API version on the classpath as well. In Bvean Validation 1.0 there is no ParameterNameProvider, so that would explain the error.Vendue
I had two additional validation-api on my classpath, but excluded them -> see my edit. Could that be the problem?Tankersley
This question may help anyone else who encounters this: #21656646Alimentation
E
4

NoSuchMethodError indicates that you have loaded wrong version of jar that has no method named like which you have used.
I highly recommend you to use hibernate 4.0 or little lower which turn out to be more stable to transplant.

Except answered 24/6, 2013 at 16:9 Comment(0)
I
1

The problem arises from having similar packaged structure jar. In my case, I had javaee6 as provided, and javax.validation1.1.0.Final both have the package javax.validation.spi.

Since I used Maven, I placed javax.validation1.1.0 dependency on top of javaee6. So I can use 1.1.0 methods. Otherwise, if the javaee6 is on top I cannot access/ override validation1.1.0 methods.

It compiled fine, but while running in Tomee 1.7.5 WebProfile I faced NoSuchMethodError. So, added the javax.validation1.1.0 Final jar to lib folder of Tomee, but still somehow javaee6 jar's validation got triggered first.

So I renamed the file javax.validation1.1.0.Final to ijavax.validation1.1.0.Final, so that when alphabetically ordered it gets loaded before javaee6, then it worked!!

Check here for class loader ordering of jars in tomcat Order of loading jar files from lib directory

Irishman answered 19/1, 2020 at 0:1 Comment(1)
This is a terrible hack that relies on internal ordering constraints that could change at any time.Chaw

© 2022 - 2024 — McMap. All rights reserved.