The @Valid annotation on a given association (i.e. object reference or collection / array of objects), dictates the Bean Validator implementation to apply recursively the bean validation routine on (each of) the associated object(s). This mechanism is recursive: an associated object can itself contain cascaded references.
Null references are ignored.
To prevent infinite loops, the Bean Validation implementation must ignore the cascading operation if the associated object instance has already been validated in the current navigation path (starting from the root object).
Example 3.8. Object graph limits
#assuming the following object graph Order -(lines)-> Orderline1 Order -(lines)-> Orderline2 Orderline1 -(order)-> Order Orderline2 -(order)-> Order Order -(customer)-> User Order -(shippingAddress)-> Address1 Order -(billingAddress)-> Address2 Address1 -(inhabitant)-> User Address2 -(inhabitant)-> User User -(addresses)-> Address1 User -(addresses)-> Address2 #validation branches are as followed Order -(lines)-> Orderline1 - order is ignored: Order is already present in the branch Order -(lines)-> Orderline2 - order is ignored: Order is already present in the branch Order -(customer)-> User -(addresses)-> Address1 - inhabitant is ignored: User is already present in the branch Order -(customer)-> User -(addresses)-> Address2 - inhabitant is ignored: User is already present in the branch Order -(shippingAddress)-> Address1 -(inhabitant)-> User - addresses to Address1 is ignored: Address1 is already present in the branch Order -(shippingAddress)-> Address1 -(inhabitant)-> User -(addresses)-> Address2 - inhabitant is ignored: User is already present in the branch Order -(shippingAddress)-> Address2 -(inhabitant)-> User - addresses to Address2 is ignored: Address2 is already present in the branch Order -(shippingAddress)-> Address2 -(inhabitant)-> User -(addresses)-> Address1 - inhabitant is ignored: User is already present in the branch Order -(billingAddress)-> Address1 -(inhabitant)-> User - addresses to Address1 is ignored: Address1 is already present in the branch Order -(billingAddress)-> Address1 -(inhabitant)-> User -(addresses)-> Address2 - inhabitant is ignored: User is already present in the branch Order -(billingAddress)-> Address2 -(inhabitant)-> User - addresses to Address2 is ignored: Address2 is already present in the branch Order -(billingAddress)-> Address2 -(inhabitant)-> User -(addresses)-> Address1 - inhabitant is ignored: User is already present in the branch
The ConstraintViolation objects, built when a failing constraint on an associated object is found, reflects the path to reach the object from the root validated object (See Section 4.2, “ConstraintViolation”).
On Wed, 18 Feb 2009 18:44:52 +0100, Emmanuel Bernard <emmanuel@hibernate.org> wrote:in the previous example, we would have two constraint violation reports:- c.b is invalid- d.b is invalidCan you tell me on which side you are?
I agree there is a problem. I don't like the idea of getting two constraint violations though.
Would it be an alternative to let ConstraintViolation.getPropertyPath() return an array of
path strings?
--Hardy