title: hibernate validator with jpa, violations on transitive @Transient @NotNull fields
body: <p>Validation using hibernate validator fails on the fields marked as <code>@Transient</code> and <code>@NotNull</code>. 
  However it fails only for those that were already stored in the DB, but now are traversed in the tree of objects. (as their value is null of course)</p>
  
  <p>For the entities like this:</p>
  
  <pre><code>public class User {
  
    @ManyToMany
    @Fetch(org.hibernate.annotations.FetchMode.JOIN)
    @Valid
    private Set&lt;Role&gt; roles;
  
    @NotNull
    private String someField;
  }
  
  public class Role {
  
    @ManyToMany
    @Fetch(org.hibernate.annotations.FetchMode.JOIN)
    @Valid
    private Set&lt;User&gt; users;
  }
  </code></pre>
  
  <p>As I do the validation of the <code>User</code> and there are more users with particular <code>Role</code> I have problem, that even if the current user validation succeeds, for the others I'm getting error.</p>
  
  <p>I do this validation on the client side prio to submitting data to server side.</p>
  
  <p>I've seen some ideas how to fix problems with validation of <code>@Transient</code> and <code>@NotNull</code>:</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/9266427/constraintviolationexception-user-entity-with-transient-confirmpassword-field">ConstraintViolationException: User Entity with transient confirmPassword field</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/7267028/ignore-transient-pattern-on-save-hibernate-entity">Ignore transient pattern on save hibernate entity</a></p></li>
  </ul>
  
  <p>However these didn't cover my case (of having violations on related objects). And moreover I didn't come to validation problems on server side yet :). As to test that would be a next step.</p>
  
  <p>So the question is, is there any way to explain validator, that transitive objects fetched from DB should be skipped during validation?</p>
  
  <p>I was thinking of extending the <code>JPATraversableResolver</code> that I currently use by overriding:</p>
  
  <pre><code> /**
       * Determine if the Bean Validation provider is allowed to reach the property state
       *
       * @param traversableObject object hosting &lt;code&gt;traversableProperty&lt;/code&gt; 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
       *        &lt;code&gt;traversableObject&lt;/code&gt;
       *        (using the path specification defined by Bean Validator).
       * @param elementType either &lt;code&gt;FIELD&lt;/code&gt; or &lt;code&gt;METHOD&lt;/code&gt;.
       *
       * @return &lt;code&gt;true&lt;/code&gt; if the Bean Validation provider is allowed to
       *         reach the property state, &lt;code&gt;false&lt;/code&gt; otherwise.
       */
       boolean isReachable(Object traversableObject,
                       Path.Node traversableProperty,
                       Class&lt;?&gt; rootBeanType,
                       Path pathToTraversableObject,
                       ElementType elementType);
  </code></pre>
  
  <p>however, I still face the problem of determining which properties to check and which not. 
  If my check would be for transient fields of the currently persisted object, I'd not cover the case of persisting entities (2 related ones), where check would be on one of them and the other one would have problematic transient field.</p>
  
  <p>Any ideas? Any experiences with that?</p>