title: Spring JPA Query for fetching latest records in a Table
body: <p>I am new to Spring JPA. I have a model in the name of Product. I am trying to write an api end point for fetching the recent records of the products table.</p>
  
  <pre><code>public static interface Repository extends PagingAndSortingRepository&lt;Product, Long&gt;
     {
        List findTop2ByOrderByIdDesc();
     }
  </code></pre>
  
  <p>When i run my application HAL Browser 
  <a href="http://localhost:8080/api/v1/products/search/findTop2ByOrderByIdDesc" rel="nofollow">http://localhost:8080/api/v1/products/search/findTop2ByOrderByIdDesc</a></p>
  
  <p>I am getting the error as </p>
  
  <pre><code>{
    "timestamp": 1440573947629,
    "status": 500,
    "error": "Internal Server Error",
    "exception": "org.springframework.dao.IncorrectResultSizeDataAccessException",
    "message": "result returns more than one elements; nested exception is javax.persistence.NonUniqueResultException: result returns more than one elements",
    "path": "/api/v1/products/search/findTop2ByOrderByIdDesc"
  }
  </code></pre>
  
  <p>How to fix this. Kindly advise</p>