-->
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.  [ 8 posts ] 
Author Message
 Post subject: Hibernate Validator ScriptAssert NoSuchElementException
PostPosted: Tue Jul 26, 2011 12:12 am 
Newbie

Joined: Mon Jul 25, 2011 11:55 pm
Posts: 7
hi,

we are starting to look into using Hibernate Validator with our Primefaces(JSF)/Spring 3.1/EclipseLink 2.3.0(JPA2) application. Following the Hibernate Validator doco we have added the required Maven dependencies. This is all working fine when we use the property level HV annotations eg @NotNull. Where we are running into trouble is when using a class level annotation including ScriptAssert. We receive the below error when running in Tomcat and trying to update a record.

NB The validation works fine in our test case when EclipseLink is not involved.

Quote:
java.util.NoSuchElementException
java.util.AbstractList$Itr.next(AbstractList.java:350)
org.eclipse.persistence.internal.jpa.metadata.listeners.BeanValidationListener$AutomaticLifeCycleValidationTraversableResolver.isRootObjectPath(BeanValidationListener.java:180)
org.eclipse.persistence.internal.jpa.metadata.listeners.BeanValidationListener$AutomaticLifeCycleValidationTraversableResolver.isReachable(BeanValidationListener.java:123)
org.hibernate.validator.engine.resolver.SingleThreadCachedTraversableResolver.isReachable(SingleThreadCachedTraversableResolver.java:46)
org.hibernate.validator.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:1242)
org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:448)
org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:397)
org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:361)
org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:313)
org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:139)
org.eclipse.persistence.internal.jpa.metadata.listeners.BeanValidationListener.validateOnCallbackEvent(BeanValidationListener.java:84)
org.eclipse.persistence.internal.jpa.metadata.listeners.BeanValidationListener.preUpdate(BeanValidationListener.java:72)



I assume it is possible to use class level validators with Eclipselink?

thanks,

Ralph


Top
 Profile  
 
 Post subject: Re: Hibernate Validator ScriptAssert NoSuchElementException
PostPosted: Wed Jul 27, 2011 3:14 am 
Hibernate Team
Hibernate Team

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

first of class level constraint should not be a problem w/ EclipseLink. In fact Bean Validation has no knowledge of JPA, except maybe the TraversableResolver implementation. If a JPA provider is detected a JPA aware traversable can be used (and is used by default by Hibernate Validator) to detect whether an association is loaded. The idea is that if the association is not loaded it must be validated correctly and does not have to be loaded and validated again.
Looking at your stack trace I would assume your problem lies somewhere within the TraversableResolver area. In fact it seems you are using a custom TraversableResolver already - AutomaticLifeCycleValidationTraversableResolver.
It would help to get some more information. How does the annotated class look like and how do you use Validator? Do you use life cycle triggered validation calls and let JPA manage the ValidatorFactory? You can try to specify a custom implementation of TraversableResolver which just true for both interface methods. You can set this custom resolver via validation.xml. This is probably not the best long term solution, but it might help to narrow down the problem.

--Hardy


Top
 Profile  
 
 Post subject: Re: Hibernate Validator ScriptAssert NoSuchElementException
PostPosted: Wed Jul 27, 2011 4:20 pm 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi,

the validation seems to be triggered automatically by EclipseLink upon persisting an entity (in BeanValidationListener#preUpdate()). I had a short look at the EclipseLink sources, the NoSuchElementException is likely caused by a javax.validation.Path passed to TraversableResolver#isReachable() which has no nodes and hence is not iterable. I'm not sure which cases there are in which such a path would be passed there. Could you possibly provide an executable test case demonstrating the issue?

Btw. the AutomaticLifeCycleValidationTraversableResolver seems to be configured explicitly by EclipseLink in BeanValidationListener, so maybe you can't override it using validation.xml as it normally should be the case.

--Gunnar

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


Top
 Profile  
 
 Post subject: Re: Hibernate Validator ScriptAssert NoSuchElementException
PostPosted: Wed Jul 27, 2011 7:52 pm 
Newbie

Joined: Mon Jul 25, 2011 11:55 pm
Posts: 7
Thank you for your replies. We managed to get it working by creating our own version of the BeanValidationListener. We found that the exception was thrown at the following code:
Code:
 
     /**
         * @return true if given path corresponds to Root Object else false.
         */
        private boolean isRootObjectPath(Path pathToTraversableObject) {
            // From Bean Validation spec section 3.5.2
            // <quote>
            //    pathToTraversableObject is the Path from the rootBeanType down to the traversableObject (it is composed of
            //    a single Node whose name is null if the root object is traversableObject). The path is described following the
            //    conventions described in Section 4.2 (getPropertyPath).
            // </quote>
            return pathToTraversableObject.iterator().next().getName() == null;
        }


By simply returning 'true' when the object is not iterable it works like a treat.

An easy way to test it is by simply using your example of @ScriptAssert where the end date has to be before the start date. Once you try to persist the entity, you will get the error.


Top
 Profile  
 
 Post subject: Re: Hibernate Validator ScriptAssert NoSuchElementException
PostPosted: Thu Jul 28, 2011 1:58 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Great that it works. Out of interest, which version of Validator are you using? 4.1 or 4.2? The path implementation has changed between these versions. I wonder whether the version would make a version.

--hardy


Top
 Profile  
 
 Post subject: Re: Hibernate Validator ScriptAssert NoSuchElementException
PostPosted: Sun Jul 31, 2011 8:29 pm 
Newbie

Joined: Mon Jul 25, 2011 11:55 pm
Posts: 7
Hi again,

we are using version 4.2

Thanks


Top
 Profile  
 
 Post subject: Re: Hibernate Validator ScriptAssert NoSuchElementException
PostPosted: Mon Aug 01, 2011 3:34 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Have you tried w/ 4.1. Just wondering whether some of the EclipseLink integration is broken due to the changes in 4.2!?


Top
 Profile  
 
 Post subject: Re: Hibernate Validator ScriptAssert NoSuchElementException
PostPosted: Mon Aug 15, 2011 6:55 am 
Newbie

Joined: Mon Jul 25, 2011 11:55 pm
Posts: 7
hi Hardy,

never got around to trying with 4.1. We have decided for the time being to do the validation in a managed bean by calling the constraint validator factory (injected by Spring). This allows us to access the class level constraints. We have turned off JPA validation as we are validating just before we do an insert/update/etc service call.

cheers,

Ralph


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.