-->
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.  [ 2 posts ] 
Author Message
 Post subject: Multiple @Valid annotations failing
PostPosted: Wed Apr 28, 2010 11:35 am 
Newbie

Joined: Wed Feb 07, 2007 1:10 pm
Posts: 7
Location: Kent, UK
Hi,

I have a J2SE (JPA) project running fine under Hibernate 3.3.2.GA, Hibernate Annotation 3.4.0.GA, Hibernate Entity Manager 3.4.0.GA & Hibernate Validator 3.1.0.GA.

I have recently upgraded the project to use Hibernate Core 3.5.1.Final (JPA2), Hibernate Validator 4.0.2 (Bean Validation 2.0).

I have made all the package import & annotation changes but am seeing a problem when I have multiple embbeded fields in an entity class, as follows:

Code:

@Entity
class Order implements Serializable {

    @Embedded
    @AssociationOverrides({
        @AssociationOverride(name="country.id", joinColumns={@JoinColumn(name="SENDER_COUNTRY")}),
    })
    @AttributeOverrides({
        @AttributeOverride(name="addressLine1", column=@Column(name="SENDER_ADDRESS_LINE_1")),
        @AttributeOverride(name="addressLine2", column=@Column(name="SENDER_ADDRESS_LINE_2")),
        @AttributeOverride(name="addressLine3", column=@Column(name="SENDER_ADDRESS_LINE_3")),
        @AttributeOverride(name="town", column=@Column(name="SENDER_TOWN")),
        @AttributeOverride(name="county", column=@Column(name="SENDER_COUNTY")),
        @AttributeOverride(name="postcode", column=@Column(name="SENDER_POSTCODE")),
    })
    @Valid
    private Address sender;

    @Embedded
    @AssociationOverrides({
        @AssociationOverride(name="country.id", joinColumns={@JoinColumn(name="RECIPIENT_COUNTRY")}),
    })
    @AttributeOverrides({
        @AttributeOverride(name="addressLine1", column=@Column(name="RECIPIENT_ADDRESS_LINE_1")),
        @AttributeOverride(name="addressLine2", column=@Column(name="RECIPIENT_ADDRESS_LINE_2")),
        @AttributeOverride(name="addressLine3", column=@Column(name="RECIPIENT_ADDRESS_LINE_3")),
        @AttributeOverride(name="town", column=@Column(name="RECIPIENT_TOWN")),
        @AttributeOverride(name="county", column=@Column(name="RECIPIENT_COUNTY")),
        @AttributeOverride(name="postcode", column=@Column(name="RECIPIENT_POSTCODE")),
    })
    @Valid
    private Address recipient;
}


When I attempt to validate this entity using:
Code:
...
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    Set<ConstraintViolation<Order>> constraintViolations = validator.validate(order);
...   


I get an error complaining that

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.validateCascadedConstraint(ValidatorImpl.java:466)
   at org.hibernate.validator.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:372)
   at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:219)
   at org.hibernate.validator.engine.ValidatorImpl.validateCascadedConstraint(ValidatorImpl.java:466)
   at org.hibernate.validator.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:372)
   at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:219)
   at org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:119)

Caused by: javax.persistence.PersistenceException: Unable to find field or method: class test.model.Address#address
   at org.hibernate.ejb.util.PersistenceUtilHelper.get(PersistenceUtilHelper.java:95)
   at org.hibernate.ejb.util.PersistenceUtilHelper.isLoadedWithReference(PersistenceUtilHelper.java:76)
   at org.hibernate.ejb.HibernatePersistence$1.isLoadedWithReference(HibernatePersistence.java:92)
   at javax.persistence.Persistence$1.isLoaded(Persistence.java:83)
   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)
   ... 17 more


If I remove one of the @Valid annotations the other one works fine, but I only get one address validated!

Many Thanks,
James

_________________
James


Top
 Profile  
 
 Post subject: Re: Multiple @Valid annotations failing
PostPosted: Thu Apr 29, 2010 7:22 am 
Hibernate Team
Hibernate Team

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

I tried a similar usecase within Hibernate Core + Validator (Order instance with two embedded entities) and it worked fine. Are you still having this problem? If so it would help if you would post your complete mappings (including Address and Country) and the session code triggering the exception.

I am a little surprised about about "Unable to find field or method: class test.model.Address#address". For some reason Validator seems to think the Address class contains a field 'address'. Does it?

--Hardy


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