jpabean-validationhibernate-validatorapache-tomeetomee-7

Hibernate as the JPA provider and Bean Validator in TomEE 7


JPA

Configured Hibernate 5.2 as JPA implementor in Apache Tomcat (TomEE)/8.5.11 (7.0.3) from this Article (TomEE 7 and Hibernate 5.2 persistence.xml)

Bean Validation

To implement Hibernate Validator as Bean Validator, placed hibernate-validator-5.4.0.Final.jar, hibernate-validator-annotation-processor-5.4.0.Final.jar, hibernate-validator-cdi-5.4.0.Final.jar in <TomEE-Home>/lib folder and removed bval-core-1.1.2.jar, bval-jsr-1.1.2.jar

But while deploying webapp gives following error:

DEBUG: No META-INF/validation.xml found. Using annotation based configuration only.
19-May-2017 09:16:14.276 SEVERE [localhost-startStop-1] org.apache.openejb.cdi.OpenEJBLifecycle.startApplication CDI Beans module deployment failed
org.apache.webbeans.exception.WebBeansDeploymentException: javax.enterprise.inject.AmbiguousResolutionException: There is more than one Bean with type javax.validation.ValidatorQualifiers: [@javax.enterprise.inject.Default()]
for injection into Field Injection Point, field name :  validator, Bean Owner : [ValidationInterceptor, WebBeansType:INTERCEPTOR, Name:null, API Types:[java.io.Serializable,java.lang.Object,org.hibernate.validator.internal.cdi.interceptor.ValidationInterceptor], Qualifiers:[javax.enterprise.inject.Default,javax.enterprise.inject.Any]]
found beans: 
Validator, WebBeansType:VALIDATION, Name:null, API Types:[java.lang.Object,javax.validation.Validator], Qualifiers:[javax.enterprise.inject.Default,javax.enterprise.inject.Any] from jar:file:/webserver/tomee/lib/javaee-api-7.0-1.jar!/javax/validation/Validator.class
ValidatorImpl, WebBeansType:THIRDPARTY, Name:null, API Types:[org.hibernate.validator.internal.engine.ValidatorImpl,javax.validation.executable.ExecutableValidator,java.lang.Object,javax.validation.Validator], Qualifiers:[javax.enterprise.inject.Default,org.hibernate.validator.cdi.HibernateValidator,javax.enterprise.inject.Any] from jar:file:/webserver/tomee/lib/hibernate-validator-5.4.0.Final.jar!/org/hibernate/validator/internal/engine/ValidatorImpl.class
at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:331)
at org.apache.openejb.cdi.OpenEJBLifecycle.startApplication(OpenEJBLifecycle.java:196)
at org.apache.openejb.cdi.ThreadSingletonServiceImpl.initialize(ThreadSingletonServiceImpl.java:189)
at org.apache.openejb.cdi.CdiBuilder.build(CdiBuilder.java:41)
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:914)
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:718)
at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1298)
at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1124)
at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:133)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:94)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5087)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:596)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1805)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.enterprise.inject.AmbiguousResolutionException: There is more than one Bean with type javax.validation.ValidatorQualifiers: [@javax.enterprise.inject.Default()]
for injection into Field Injection Point, field name :  validator, Bean Owner : [ValidationInterceptor, WebBeansType:INTERCEPTOR, Name:null, API Types:[java.io.Serializable,java.lang.Object,org.hibernate.validator.internal.cdi.interceptor.ValidationInterceptor], Qualifiers:[javax.enterprise.inject.Default,javax.enterprise.inject.Any]]

How to resolve this problem????


Solution

  • As specified in Hibernate Validator documentation (here), If application runs in an environment which does not provide CDI integration out of the box, you may use the Hibernate Validator CDI portable extension by adding the hibernate-validator-cdi

    Apache Tomcat (TomEE)/8.5.11 (7.0.3) implements CDI with Apache OpenWebBeans out of the box.

    Problem resolved after removing the hibernate-validator-cdi-5.4.0.Final.jar from <TomEE>/lib folder.