title: Entity validation before the "beforeSave" RepositoryEventHandler fired
body: <p>The <a href="http://docs.spring.io/spring-data/rest/docs/current/reference/html/" rel="nofollow noreferrer">Spring Data REST docs</a> describe the way to validate entities <em>after</em> the <code>RepositoryEventHandler</code> has fired:</p>
  
  <blockquote>
    <p>you simply need to register an instance of your validator with the
    bean whose job it is to invoke validators <strong>after</strong> the correct event</p>
  </blockquote>
  
  <p>Is there a way to apply [declarative] JSR-303 validation of entities <em>before</em> they get passed to the "beforeSave" <code>RepositoryEventHandler</code>s? </p>
  
  <p>From what I can see so far debugging, that is not the case and the "beforeSave" <code>RepositoryEventHandler</code>s get fired before any validation takes place.</p>
  
  <p>I can write validating calls in the handlers directly, but that would be different from how the "after" validation is handled.</p>
  
  <p>Btw. the sequence of event handler calls seems to have changed between Spring Boot 1.3.8 and 1.5.1. In the past, the validation occurred <em>before</em> the <code>@HandleBeforeSave</code> handler. In the 1.5.1 <code>ValidatingRepositoryEventListener</code> fires <em>after</em> the <code>@HandleBeforeSave</code> handlers.</p>
  
  <p>Update:</p>
  
  <p>As mentioned in the comments, there seems to be a <a href="https://jira.spring.io/browse/DATAREST-685" rel="nofollow noreferrer">ticket</a> in Spring Data REST Jira is open about this.</p>