This topic has not yet been written. The content below is from the topic description.
5.4. TraversableResolver The usage of the TraversableResolver has so far not been discussed. The idea is that in some cases, the state of a property should not be accessed. The most obvious example for that is a lazy loaded property or association of a Java Persistence provider. Validating this lazy property or association would mean that its state would have to be accessed triggering a load from the database. Bean Validation controls which property can and cannot be accessed via the TraversableResolver interface (see Example 5.8, “TraversableResolver interface”). In the example HibernateValidatorConfiguration. Example 5.8. TraversableResolver interface /** * Contract determining if a property can be accessed by the Bean Validation provider * This contract is called for each property that is being either validated or cascaded. * * A traversable resolver implementation must be thread-safe. * */ public interface TraversableResolver { /** * Determine if the Bean Validation provider is allowed to reach the property state * * @param traversableObject object hosting traversableProperty or null * if validateValue is called * @param traversableProperty the traversable property. * @param rootBeanType type of the root object passed to the Validator. * @param pathToTraversableObject path from the root object to * traversableObject * (using the path specification defined by Bean Validator). * @param elementType either FIELD or METHOD. * * @return true if the Bean Validation provider is allowed to * reach the property state, false otherwise. */ boolean isReachable(Object traversableObject, Path.Node traversableProperty, Class rootBeanType, Path pathToTraversableObject, ElementType elementType); /** * Determine if the Bean Validation provider is allowed to cascade validation on * the bean instance returned by the property value * marked as @Valid. * Note that this method is called only if isReachable returns true for the same set of * arguments and if the property is marked as @Valid * * @param traversableObject object hosting traversableProperty or null * if validateValue is called * @param traversableProperty the traversable property. * @param rootBeanType type of the root object passed to the Validator. * @param pathToTraversableObject path from the root object to * traversableObject * (using the path specification defined by Bean Validator). * @param elementType either FIELD or METHOD. * * @return true if the Bean Validation provider is allowed to * cascade validation, false otherwise. */ boolean isCascadable(Object traversableObject, Path.Node traversableProperty, Class rootBeanType, Path pathToTraversableObject, ElementType elementType); } Hibernate Validator provides two TraversableResolvers out of the box which will be enabled automatically depending on your environment. The first is the DefaultTraversableResolver which will always return true for isReachable() and isTraversable(). The second is the JPATraversableResolver which gets enabled when Hibernate Validator gets used in combination with JPA 2. In case you have to provide your own resolver you can do so again using the Configuration object as seen in Example 5.9, “Providing a custom TraversableResolver”. Example 5.9. Providing a custom TraversableResolver Configuration configuration = Validation.byDefaultProvider().configure(); ValidatorFactory factory = configuration .traversableResolver(new MyTraversableResolver()) .buildValidatorFactory(); Validator validator = factory.getValidator();