Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Validator: Exception in TraversableResolver.isReachable
PostPosted: Fri Dec 04, 2009 2:20 pm 
Newbie

Joined: Fri Dec 04, 2009 1:58 pm
Posts: 7
Location: Dublin, Ireland
Hello,

I'm trying to validate a bean with a custom class level constraint. Problem is when validating, I got this: javax.validation.ValidationException: Call to TraversableResolver.isReachable() threw an exception.

The problem is isolated to the custom class level constraint: if I remove that and leave all the others, the validation goes on.

Call that fails:
Code:
Set<ConstraintViolation<NewUser>> result = this.validator.validate(newUser);


The custom constraint is:
Code:
@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = PasswordVerificationValidator.class)
public @interface PasswordVerification {

    String message() default "Password verification failed";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

}


And the validator code is:
Code:
public class PasswordVerificationValidator implements ConstraintValidator<PasswordVerification, NewUser>{

   @Override
   public void initialize(PasswordVerification constraintAnnotation) {
   }

   @Override
   public boolean isValid(NewUser value, ConstraintValidatorContext context) {
      return true; // By now, always valid
   }

}


The bean to which I apply this is:
Code:
@PasswordVerification
public class NewUser implements Serializable {
   
   @NotNull
   @Email
   @Size(min=4, max=200)
   private String username;
   
   @NotNull
   @Size(min=4)
   private String password;
   
   @NotNull
   private String passwordVerification;

   // Getters/setters
   [...]
}   


And the relevant parts of the stacktrace are:
Code:
java.lang.NullPointerException
     at java.lang.Class.searchFields(Class.java:2616)
     at java.lang.Class.getField0(Class.java:2635)
     at java.lang.Class.getField(Class.java:1535)
     at org.hibernate.ejb.util.PersistenceUtilHelper.get(PersistenceUtilHelper.java:84)
     at org.hibernate.ejb.util.PersistenceUtilHelper.isLoadedWithReference(PersistenceUtilHelper.java:76)
     at org.hibernate.ejb.HibernatePersistence$1.isLoadedWithReference(HibernatePersistence.java:167)
     at javax.persistence.Persistence$1.isLoaded(Persistence.java:81)
     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)
     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 org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:89)
     at java.lang.reflect.Method.invoke(Method.java:616)
     at org.apache.wicket.proxy.LazyInitProxyFactory$JdkHandler.invoke(LazyInitProxyFactory.java:416)
     at org.apache.wicket.proxy.$Proxy2.validate(Unknown Source)
     at net.carinae.dev.prototipo3.web.pages.UserRegistrationPage$RegistrationForm.onSubmit(UserRegistrationPage.java:72)
     at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1518)
     at org.apache.wicket.markup.html.form.Form.process(Form.java:914)
     at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:876)
     at java.lang.reflect.Method.invoke(Method.java:616)
     at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
     at org.apache.wicket.request.target.component.BookmarkableListenerInterfaceRequestTarget.processEvents(BookmarkableListenerInterfaceRequestTarget.java:161)
     at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
     at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
     at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
     at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
     at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
     at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:468)
     at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:301)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:344)
     at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:80)
     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:356)
     at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:150)
     at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
     at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
     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:233)
     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
     at java.lang.Thread.run(Thread.java:636)


And:
Code:
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 org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:89)
     at java.lang.reflect.Method.invoke(Method.java:616)
     at org.apache.wicket.proxy.LazyInitProxyFactory$JdkHandler.invoke(LazyInitProxyFactory.java:416)
     at org.apache.wicket.proxy.$Proxy2.validate(Unknown Source)
     at net.carinae.dev.prototipo3.web.pages.UserRegistrationPage$RegistrationForm.onSubmit(UserRegistrationPage.java:72)
     at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1518)
     at org.apache.wicket.markup.html.form.Form.process(Form.java:914)
     at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:876)
     at java.lang.reflect.Method.invoke(Method.java:616)
     at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
     at org.apache.wicket.request.target.component.BookmarkableListenerInterfaceRequestTarget.processEvents(BookmarkableListenerInterfaceRequestTarget.java:161)
     at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
     at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
     at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
     at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
     at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
     at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:468)





Hibernate Validor Version is 4.0.2.GA.

Any help appreciated :-)

Thanks.


Top
 Profile  
 
 Post subject: Re: Validator: Exception in TraversableResolver.isReachable
PostPosted: Fri Dec 04, 2009 2:37 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hmm, sounds like this bug - HV-266. So far I could not reproduce it.
It looks like you are also using Hibernate Core since JPATraversableResolver gets called (if not something went wrong in the configuration, since JPATraversableResolver should not be used in this case). How does your Hibernate Configuration look like and which exact Hibernate version are you using?
JPATraversableResolver is really intended to be used with JPA 2 and the Hibernate 3.5. I am not even sure whether PersistenceUtilHelper is fully operational yet.

I will try to reproduce the problem with your testcase. It would be great if you could provide more details about your setup.

--Hardy


Top
 Profile  
 
 Post subject: Re: Validator: Exception in TraversableResolver.isReachable
PostPosted: Fri Dec 04, 2009 3:00 pm 
Newbie

Joined: Fri Dec 04, 2009 1:58 pm
Posts: 7
Location: Dublin, Ireland
Hi,

yes, I'm using Hibernate 3.5.0-Beta-2 as a JPA2 provider. I didn't mention it as the affected class is not an entity.

My persistence.xml file is:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">

   <persistence-unit name="myPersistenceUnit" transaction-type="RESOURCE_LOCAL">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
         <property name="hibernate.hbm2ddl.auto" value="create" />
         <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy" />
      </properties>
   </persistence-unit>
   
</persistence>


Rest of the configuration is all done with annotations.

In case it matters, I'm using Spring3 to provide the entity manager. The relevant part in its applicationContext.xml file is:

Code:
    <!-- JPA Entity Manager -->
    <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="myEntityManagerFactory">
        <property name="dataSource" ref="myDataSource"/>
    </bean>


Any more information that you need about my setup, just ask.

Thanks for the quick reply :-)


Top
 Profile  
 
 Post subject: Re: Validator: Exception in TraversableResolver.isReachable
PostPosted: Fri Dec 04, 2009 3:08 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Quote:

yes, I'm using Hibernate 3.5.0-Beta-2 as a JPA2 provider. I didn't mention it as the affected class is not an entity.


Interesting, that might actually be the problem. I'm not sure whether JPATraversableResolver actually caters for the fact that the entity you are trying to validate is a managed entity or not.

--Hardy


Top
 Profile  
 
 Post subject: Re: Validator: Exception in TraversableResolver.isReachable
PostPosted: Fri Dec 04, 2009 3:34 pm 
Newbie

Joined: Fri Dec 04, 2009 1:58 pm
Posts: 7
Location: Dublin, Ireland
In case it helps, if I convert it to an entity (with the @Entity annotation, and making the username the id) the problem persists.


Top
 Profile  
 
 Post subject: Re: Validator: Exception in TraversableResolver.isReachable
PostPosted: Fri Dec 04, 2009 4:03 pm 
Newbie

Joined: Fri Dec 04, 2009 1:58 pm
Posts: 7
Location: Dublin, Ireland
I created a minimal project (except for the pom dependencies) that replicates the problem.

It can be downloaded in here:
http://carinae.net/test-validation.tar.gz

Hope it helps.


Top
 Profile  
 
 Post subject: Re: Validator: Exception in TraversableResolver.isReachable
PostPosted: Tue Mar 02, 2010 10:59 pm 
Newbie

Joined: Sat Feb 27, 2010 9:16 pm
Posts: 3
I get the same problem. Any news about it?

Thanks,

Tiago Peixoto.


Top
 Profile  
 
 Post subject: Re: Validator: Exception in TraversableResolver.isReachable
PostPosted: Wed Mar 03, 2010 6:37 am 
Newbie

Joined: Fri Dec 04, 2009 1:58 pm
Posts: 7
Location: Dublin, Ireland
The problem is fixed if you use the latest Validator 4.1.0-Snapshot and Hibernate 3.5-CR-2.


Top
 Profile  
 
 Post subject: Re: Validator: Exception in TraversableResolver.isReachable
PostPosted: Mon Mar 15, 2010 7:58 am 
Newbie

Joined: Fri Mar 12, 2010 9:42 am
Posts: 19
Looks like the snapshots have disappeared from the JBoss repository:
http://snapshots.jboss.org/maven2/org/h ... -SNAPSHOT/

Anyone know where I can find them?

I think I found them there last week, but couldn't get it to work on Glassfish, I get the same exception as above. Anyone tried this? How can I override the hibernate-validator version bundled with Glassfish?

Regards, Anders


Top
 Profile  
 
 Post subject: Re: Validator: Exception in TraversableResolver.isReachable
PostPosted: Mon Mar 15, 2010 8:23 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
The SNAPSHOT expired. SNAPSHOTS in this repo only stay there for a couple of months. I pushed a new SNAPSHOT.
Work on the first beta release of 4.1.0 is on its way and a release should be out soon.

--Hardy


Top
 Profile  
 
 Post subject: Re: Validator: Exception in TraversableResolver.isReachable
PostPosted: Mon Mar 15, 2010 9:25 am 
Newbie

Joined: Fri Mar 12, 2010 9:42 am
Posts: 19
Great, found it.

But no matter what I try, Glassfish V3 won't pick up the provided Hibernate Validator version. It looks like it uses a bean-validator.jar in glassfish/modules, and this jar contains some classes that are not provided in Hibernate Validator (javax/validation/.., org/glassfish/.., org/slf4j/.. etc.). I have tried putting hibernate-validator in both the root lib folder and the domain lib folder, no difference.

Any suggestions on how I can force Glassfish to use the provided validator version?


Top
 Profile  
 
 Post subject: Re: Validator: Exception in TraversableResolver.isReachable
PostPosted: Thu Mar 18, 2010 12:26 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
No idea how the glassfish integration of bean validation is implemented/bundled. You are probably best of asking there. The classes you see missing are the dependencies of Hibernate Validator. java.validation are the Bean Validation specification classes and org.slf4j are the logging framework classes. You would have to add these dependencies as well. Look at the maven pom to see what is required. Now, why bean-validator.jar seems to contain all this is not quite clear to me. That seems to be against modularization.

If you find out how it works in Glassfish let us know :)

--Hardy


Top
 Profile  
 
 Post subject: Re: Validator: Exception in TraversableResolver.isReachable
PostPosted: Fri Mar 19, 2010 4:21 am 
Newbie

Joined: Fri Mar 12, 2010 9:42 am
Posts: 19
I managed to update Hibernate Validator by manually replacing all classes under org.hibernate in bean-validator.jar. And this solved the issue, class level validation now works.

I wonder if it will be possible to update Hibernate Validator to 4.1.0 when it is released, using the Glassfish update tool.


Top
 Profile  
 
 Post subject: Re: Validator: Exception in TraversableResolver.isReachable
PostPosted: Fri Mar 19, 2010 7:44 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
You might be, but replacing classes in a jar file seems to be wrong. Surely the Glassfish guys must have thought about an easier way to upgrade Validator !?


Top
 Profile  
 
 Post subject: Re: Validator: Exception in TraversableResolver.isReachable
PostPosted: Thu Apr 01, 2010 7:41 am 
Newbie

Joined: Sat Feb 27, 2010 9:16 pm
Posts: 3
Ok, worked with hibernate-validator-4.1.0.Beta1.

Thanks.


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