title: JPA Repository findAll with optional fields
body: <p>I have a controller try to search with optional field.
  The JPA entity class is defined as:</p>
  <pre class="lang-java prettyprint-override"><code>package demo;
  
  import javax.persistence.*;
  
  @Entity
  public class UploadFile {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    private String name;
  
    public UploadFile() {
    }
  
    public UploadFile(String name) {
      this.name = name;
    }
  
    public String getName() {
      return name;
    }
  
    public void setName(String name) {
      this.name = name;
    }
  
    public int getId() {
      return id;
    }
  
    public void setId(int id) {
      this.id = id;
    }
  
    @Override
    public String toString() {
      return &quot;UploadFile{&quot; +
          &quot;id=&quot; + id +
          &quot;, name='&quot; + name + '\'' +
          '}';
    }
  
  }
  </code></pre>
  <p>The controller is defined in the following code:</p>
  <pre class="lang-java prettyprint-override"><code>@RequestMapping(value = &quot;/searchFile&quot;, method = RequestMethod.GET)
  public @ResponseBody
  List&lt;UploadFile&gt; searchFile(@RequestParam(&quot;id&quot;) Optional&lt;Integer&gt; id, @RequestParam(&quot;name&quot;) Optional&lt;String&gt; name) {
      UploadFile newFile = new UploadFile();
      if (id.isPresent()) {
          newFile.setId(id.get());
      }
      if (name.isPresent()) {
          newFile.setName(name.get());
      }
      System.out.println(&quot;new File: &quot; + newFile);
  
      //uploadFileRepository is a JpaRepository Class
      return List&lt;UploadFile&gt; files = uploadFileRepository.findAll(Example.of(newFile));
  }
  </code></pre>
  <p>The database has one record:</p>
  <pre><code>ID      NAME    SIZE    TYPE  
  1       index   111     html
  </code></pre>
  <p>When '/searchFile?id=1' hits server, the console prints:</p>
  <pre><code>new File: UploadFile{id=1, name='null'}
  </code></pre>
  <p>The http returns an empty array:</p>
  <p>I want the <code>/searchFile?id=1</code> to return the record with id 1,
  and also <code>/searchFile?name=index</code> to return the record with id 1 too.</p>
  <p>Is there anything I did wrong?</p>
  <p>Thanks!</p>