title: Difference between findBy and findOneBy in Spring data JPA
body: <p>All i know so far is that FindBy can return multiple results while FindOneBy will return a single result or null when we use it the following way.</p>
  
  <pre><code>List&lt;Department&gt; findByDepartmentName(String name);
  Department findOneByDepartmentId(Long Id);
  </code></pre>
  
  <p>now, my question is, can i use findBy this way?</p>
  
  <pre><code>Department  findByDepartmentId(Long Id);
  </code></pre>
  
  <p>If yes,</p>
  
  <ul>
  <li>Lets assume there are multiple records for given Id.</li>
  <li>On what basis does <em>findBydepartmentId</em>  return a single record?</li>
  </ul>
  
  <p>Finally, When or Why should i not use  findBy in place of findOneBy?</p>