-->
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: Hibernate Validator 4.1.0.Final and JBoss 5.1.0
PostPosted: Thu Jul 08, 2010 4:35 pm 
Newbie

Joined: Fri Aug 05, 2005 2:56 pm
Posts: 11
I have a simple JUnit test working with the newly released version of the Hibernate Validator 4.1.0.Final but when I attempt to execute the validation in my WebService/EJB in JBoss 5.1.0 I am confronted with the following exception:

Here is an example method in which I am trying to run some validation code.

Code:
public Configuration read(Integer anID)   throws ServiceException {

   // Retrieve the Configuration
   Configuration configuration = this.getConfigurationPersistentManager().findById(anID);
      
   ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
   validator = factory.getValidator();   
   Set<ConstraintViolation<Configuration>> constraintViolations = validator.validate(configuration);
      
   return configuration;
}


Here is the exception:
Code:
16:22:54,125 ERROR [InvocationHandlerJAXWS] Method invocation failed with exception: null
java.lang.reflect.InvocationTargetException
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.jboss.webservices.integration.invocation.AbstractInvocationHandlerJSE.invoke(AbstractInvocationHandlerJSE.java:129)
   at org.jboss.wsf.stack.cxf.AbstractInvoker._invokeInternal(AbstractInvoker.java:154)
   at org.jboss.wsf.stack.cxf.AbstractInvoker.invoke(AbstractInvoker.java:104)
   at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
   at java.util.concurrent.FutureTask.run(FutureTask.java:138)
   at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
   at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:98)
   at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
   at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:104)
   at org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:99)
   at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:452)
   at org.jboss.wsf.stack.cxf.ServletControllerExt.invoke(ServletControllerExt.java:175)
   at org.jboss.wsf.stack.cxf.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:61)
   at org.jboss.wsf.stack.cxf.CXFServletExt.invoke(CXFServletExt.java:148)
   at org.apache.cxf.transport.servlet.AbstractCXFServlet.doPost(AbstractCXFServlet.java:153)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
   at org.apache.cxf.transport.servlet.AbstractCXFServlet.service(AbstractCXFServlet.java:211)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
   at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
   at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
   at java.lang.Thread.run(Thread.java:619)
Caused by: javax.validation.ValidationException: Call to TraversableResolver.isReachable() threw an exception
   at org.hibernate.validator.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:773)
   at org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:331)
   at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForRedefinedDefaultGroup(ValidatorImpl.java:278)
   at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:260)
   at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:213)
   at org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:119)
   at com.thesearchagency.service.influencer.impl.InfluencerService.read(InfluencerService.java:75)
   ... 43 more
[color=#80FF80]Caused by: java.lang.ClassCastException: org.hibernate.ejb.HibernatePersistence cannot be cast to javax.persistence.spi.PersistenceProvider
   at javax.persistence.Persistence$1.isLoaded(Persistence.java:77)
   at org.hibernate.validator.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:33)
   at org.hibernate.validator.engine.resolver.DefaultTraversableResolver.isReachable(DefaultTraversableResolver.java:112)
   at org.hibernate.validator.engine.resolver.SingleThreadCachedTraversableResolver.isReachable(SingleThreadCachedTraversableResolver.java:47)
   at org.hibernate.validator.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:764)
   ... 49 more[/color]
16:22:54,125 WARNING [PhaseInterceptorChain] Application has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Call to TraversableResolver.isReachable() threw an exception
   at org.jboss.wsf.stack.cxf.AbstractInvoker.createFault(AbstractInvoker.java:209)
   at org.jboss.wsf.stack.cxf.AbstractInvoker._invokeInternal(AbstractInvoker.java:174)
   at org.jboss.wsf.stack.cxf.AbstractInvoker.invoke(AbstractInvoker.java:104)
   at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
   at java.util.concurrent.FutureTask.run(FutureTask.java:138)
   at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
   at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:98)
   at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
   at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:104)
   at org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:99)
   at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:452)
   at org.jboss.wsf.stack.cxf.ServletControllerExt.invoke(ServletControllerExt.java:175)
   at org.jboss.wsf.stack.cxf.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:61)
   at org.jboss.wsf.stack.cxf.CXFServletExt.invoke(CXFServletExt.java:148)
   at org.apache.cxf.transport.servlet.AbstractCXFServlet.doPost(AbstractCXFServlet.java:153)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
   at org.apache.cxf.transport.servlet.AbstractCXFServlet.service(AbstractCXFServlet.java:211)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
   at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
   at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
   at java.lang.Thread.run(Thread.java:619)
[color=#80FF80]Caused by: javax.validation.ValidationException: Call to TraversableResolver.isReachable() threw an exception
   at org.hibernate.validator.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:773)
   at org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:331)
   at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForRedefinedDefaultGroup(ValidatorImpl.java:278)
   at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:260)
   at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:213)
   at org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:119)
   at com.thesearchagency.service.influencer.impl.InfluencerService.read(InfluencerService.java:75)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.jboss.webservices.integration.invocation.AbstractInvocationHandlerJSE.invoke(AbstractInvocationHandlerJSE.java:129)
   at org.jboss.wsf.stack.cxf.AbstractInvoker._invokeInternal(AbstractInvoker.java:154)
   ... 37 more
Caused by: java.lang.ClassCastException: org.hibernate.ejb.HibernatePersistence cannot be cast to javax.persistence.spi.PersistenceProvider
   at javax.persistence.Persistence$1.isLoaded(Persistence.java:77)
   at org.hibernate.validator.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:33)
   at org.hibernate.validator.engine.resolver.DefaultTraversableResolver.isReachable(DefaultTraversableResolver.java:112)
   at org.hibernate.validator.engine.resolver.SingleThreadCachedTraversableResolver.isReachable(SingleThreadCachedTraversableResolver.java:47)
   at org.hibernate.validator.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:764)
   ... 49 more[/color]


I am assuming this is some sort of classloader issue in JBoss 5.1.0.
I have tried a few different jboss-app classloader configuration(s) but none have worked yet.
My jboss-app.xml is located int he root of my EAR file

jboss-app.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-app>
   <loader-repository>com.thesearchagency.services:archive=Influencer-Service-Loader-Repository
      <loader-repository-config>java2ParentDelegation=false</loader-repository-config>
   </loader-repository>
</jboss-app>


Maven Dependecies
Code:
<dependencies>
   
   <dependency>
      <groupId>javax.xml.bind</groupId>
      <artifactId>jaxb-api</artifactId>
      <version>2.1</version>
      <scope>provided</scope>
   </dependency>

   <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-validator</artifactId>
      <version>4.1.0.Beta1</version>
      <scope>compile</scope>         
   </dependency>

   <dependency>
      <groupId>org.hibernate.javax.persistence</groupId>
      <artifactId>hibernate-jpa-2.0-api</artifactId>
      <version>1.0.0.Final</version>
      <scope>compile</scope>      
   </dependency>

   <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>1.5.6</version>
   </dependency>

</dependencies>


I am assuming this is some sort of classloader issue in JBoss 5.1.0. Any help with this would be much appreciated.

Regards,
Kyle


Top
 Profile  
 
 Post subject: Hibernate Validator 4.1.0.Final and JBoss 5.1.0 runtime issu
PostPosted: Fri Jul 09, 2010 10:42 am 
Newbie

Joined: Fri Aug 05, 2005 2:56 pm
Posts: 11
Anybody have any ideas or been successful using the Hibernate Validator 4.1.0.Final with JBoss 5.1.0 ???


Top
 Profile  
 
 Post subject: Re: Hibernate Validator 4.1.0.Final and JBoss 5.1.0
PostPosted: Tue Jul 13, 2010 11:24 am 
Newbie

Joined: Fri Aug 05, 2005 2:56 pm
Posts: 11
Okay so I was able to work around this issue by implementing a TraversableResolver and setting it on the Validator like so:

Code:
public class MyTraversableResolver implements TraversableResolver {
   
     public boolean isReachable(Object traversableObject, Path.Node traversableProperty, Class rootBeanType, Path pathToTraversableObject, ElementType elementType) {
        return true;
     }

     public boolean isCascadable(Object traversableObject, Path.Node traversableProperty, Class rootBeanType, Path pathToTraversableObject, ElementType elementType) {
        return true;
     }
}


Code:
public class SimpleObject{
   
   ....

   @NotNull   
   @Size(min=0, max=Integer.MAX_VALUE)
   private Integer id;
}



Code Snippet
Code:
     TraversableResolver tr = new MyTraversableResolver();
     Validator validator = Validation.buildDefaultValidatorFactory().usingContext().traversableResolver(tr).getValidator();   
     Set<ConstraintViolation<SimpleObject>> constraintViolations = validator.validate(simpleObject);



When I run this on JBoss 5.1.0 I receive the following exception when I attempt to validate the SimpleObject:

Code:
Caused by: javax.validation.UnexpectedTypeException: No validator could be found for type: java.lang.Integer
   at org.hibernate.validator.engine.ConstraintTree.verifyResolveWasUnique(ConstraintTree.java:240)
   at org.hibernate.validator.engine.ConstraintTree.findMatchingValidatorClass(ConstraintTree.java:223)
   at org.hibernate.validator.engine.ConstraintTree.getInitializedValidator(ConstraintTree.java:171)
   at org.hibernate.validator.engine.ConstraintTree.validateConstraints(ConstraintTree.java:127)
   at org.hibernate.validator.metadata.MetaConstraint.validateConstraint(MetaConstraint.java:121)
   at org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:334)
   at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForRedefinedDefaultGroup(ValidatorImpl.java:278)
   at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:260)
   at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:213)
   at org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:119)
   at com.thesearchagency.service.influencer.impl.InfluencerService.addBucket(InfluencerService.java:118)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.jboss.webservices.integration.invocation.AbstractInvocationHandlerJSE.invoke(AbstractInvocationHandlerJSE.java:129)
   at org.jboss.wsf.stack.cxf.AbstractInvoker._invokeInternal(AbstractInvoker.java:154)
   ... 37 more




I have seen a few mentions of this doing a quick Google search but no resolutions. I am hoping this is because I am doing something obviously simple the wrong way? Any ideas anyone???


Top
 Profile  
 
 Post subject: Re: Hibernate Validator 4.1.0.Final and JBoss 5.1.0
PostPosted: Tue Jul 13, 2010 12:37 pm 
Newbie

Joined: Fri Aug 05, 2005 2:56 pm
Posts: 11
Ignore my post. I now realize that @Size should only be used with String, Collection, Map and arrays.

Everything works like a champ now!

-Kyle


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.