title: Appending custom conditions on spring data jpa repository method queries
body: <p><strong>Short Version</strong></p>
  
  <p>I am looking for a way to have all the findBy methods of a repository class appended with a particular condition</p>
  
  <p><strong>Full Version</strong></p>
  
  <p>Let's assume I have a Product entity and Customer entity. Both of them extends the OwnerAwareEntity and they inherit ownerRef field which identifies the owner of the entity( It could be a merchant or a partner ). I want to have the findBy methods of the Product and Customer modified in runtime such that they are appended with an additional condition of the ownerRef. The ownerRef value could be identified from the user session.</p>
  
  <p><strong>Example</strong> </p>
  
  <p>The parent entity class that provides the common ownerRef field</p>
  
  <pre><code>public class OwnerAwareEntity implements Serializable {
  
   private String ownerRef;
  
  }
  </code></pre>
  
  <p>Customer entity extending OwnerAwareEntity</p>
  
  <pre><code>public class Customer extends OwnerAwareEntity {
  
    private String firstname;
  
    private String mobile ;
  
  }
  </code></pre>
  
  <p>Product entity extending OwnerAwareEntity</p>
  
  <pre><code>public class Product extends OwnerAwareEntity {
  
    private String code;
  
    private String name;
  
  }
  </code></pre>
  
  <p>Repository class for Product &amp; Customer extending an OwnerAwareRepository </p>
  
  <pre><code>public interface OwnerAwareRepository extends JpaRepository {
  
  }
  
  public interface ProductRepository extends OwnerAwareRepository {
  
    Product findByCode(String code );
  
  }
  
  public interface CustomerRepository extends OwnerAwareRepository {
  
    Customer findByFirstname(String firstname );
  
  }
  </code></pre>
  
  <p>This, when executed, should result in a query like below</p>
  
  <pre><code>select P from Product P where P.code=?1 and P.ownerRef='aValue'
  &amp;
  select C from Customer C where C.firstname=?1 and C.ownerRef='aValue'
  </code></pre>
  
  <p>What should be my approach to have this appending of condition achieved?. I only want this appending to be happening when the parent repository is OwnerAwareRepository.</p>