This topic has not yet been written. The content below is from the topic description.
2.1.5. Object graphs The Bean Validation API does not only allow to validate single class instances but also complete object graphs. To do so, just annotate a field or property representing a reference to another object with @Valid. If the parent object is validated, all referenced objects annotated with @Valid will be validated as well (as will be their children etc.). See Example 2.6, “Adding a driver to the car”. Example 2.5. Class Person package com.mycompany; import javax.validation.constraints.NotNull; public class Person { @NotNull private String name; public Person(String name) { super(); this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } } Example 2.6. Adding a driver to the car package com.mycompany; import javax.validation.Valid; import javax.validation.constraints.NotNull; public class Car { @NotNull @Valid private Person driver; public Car(Person driver) { this.driver = driver; } //getters and setters ... } If an instance of Car is validated, the referenced Person object will be validated as well, as the driver field is annotated with @Valid. Therefore the validation of a Car will fail if the name field of the referenced Person instance is null. Object graph validation also works for collection-typed fields. That means any attributes that are arrays implement java.lang.Iterable (especially Collection, List and Set) implement java.util.Map can be annotated with @Valid, which will cause each contained element to be validated, when the parent object is validated. Example 2.7. Car with a list of passengers package com.mycompany; import java.util.ArrayList; import java.util.List; import javax.validation.Valid; import javax.validation.constraints.NotNull; public class Car { @NotNull @Valid private List passengers = new ArrayList(); public Car(List passengers) { this.passengers = passengers; } //getters and setters ... } If a Car instance is validated, a ConstraintValidation will be created, if any of the Person objects contained in the passengers list has a null name. Note null values are getting ignored when validating object graphs.