title: Spring Data JPA: having mandatory and optional fields in query by example
body: <p>Is there a way in the query by example to specify which field condition needs to be fulfilled and which one not?</p>
  
  <p>If I have an entity:</p>
  
  <pre><code>   @Entity
      public class Person extends EntityBase {
      @Size(max = 50)
      @NotNull
      private String firstName;
  
      @NotNull
      @Size(max = 80)
      private String lastName;
  
      @NotNull
      @Size(max = 100)
      private Status status;
     }
  </code></pre>
  
  <p>Is there a way that I query all persons that have a specific status and either firstName or lastName equal to something?</p>
  
  <p>Something like status = Active AND (firstName = "name" OR lastName = "name")</p>
  
  <p>If I do:</p>
  
  <pre><code>Example&lt;Person&gt; example = Example.of(new Person("name", "name", Status.Active));
  repo.findAll(example);
  </code></pre>
  
  <p>I have possiblity with the matchers to specify whether all fields should match or any field should match, can I do combination?
  If it's not possible with query by example, what other way do you recommend?</p>