title: Spring Data: default 'not deleted' logic for automatic method-based queries when using soft-delete policy
body: <p>Let's say we use soft-delete policy: nothing gets deleted from the storage; instead, a 'deleted' attribute/column is set to true on a record/document/whatever to make it 'deleted'. Later, only non-deleted entries should be returned by query methods.</p>
  
  <p>Let's take MongoDB as an example (alghough JPA is also interesting).</p>
  
  <p>For standard methods defined by <code>MongoRepository</code>, we can extend the default implementation (<code>SimpleMongoRepository</code>), override the methods of interest and make them ignore 'deleted' documents.</p>
  
  <p>But, of course, we'd also like to use custom query methods like</p>
  
  <pre><code>List&lt;Person&gt; findByFirstName(String firstName)
  </code></pre>
  
  <p>In a soft-delete environment, we are forced to do something iike</p>
  
  <pre><code>List&lt;person&gt; findByFirstNameAndDeletedIsFalse(String firstName)
  </code></pre>
  
  <p>or write queries manually with <code>@Query</code> (adding the same boilerplate condition about 'not deleted' all the time).</p>
  
  <p><strong>Here comes the question</strong>: is it possible to add this 'non-deleted' condition to any generated query automatically? I did not find anything in the documentation.</p>
  
  <p>I'm looking at Spring Data (Mongo and JPA) 2.1.6.</p>
  
  <h3>Similar questions</h3>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/43807143/query-interceptor-for-spring-data-mongodb-for-soft-deletions">Query interceptor for spring-data-mongodb for soft deletions</a> here they suggest Hibernate's <code>@Where</code> annotation which only works for JPA+Hibernate, and it is not clear how to override it if you still need to access deleted items in some queries</li>
  <li><a href="https://stackoverflow.com/questions/19323557/handling-soft-deletes-with-spring-jpa">Handling soft-deletes with Spring JPA</a> here people either suggest the same <code>@Where</code>-based approach, or the solution applicability is limited with the already-defined standard methods, not the custom ones.</li>
  </ol>