title: How to fetch list of objects with same phone number
body: <p>I have an entity for <code>driving_info</code> with lot of fields but one of them is a phone number ( from which was ordered ).
  What I am trying to do is to fetch all drives that were ordered from that number. But when I try to pass the int of <code>phoneNumber</code> I get</p>
  <pre><code>query did not return a unique result: 5; nested exception is javax.persistence.NonUniqueResultException: query did not return a unique result: 5
  org.springframework.dao.IncorrectResultSizeDataAccessException: query did not return a unique result: 5; nested exception is javax.persistence.NonUniqueResultException: query did not return a unique result: 5
  </code></pre>
  <p>I actually want the list of results so that I can get a response of list of all drives that were ordered from that phone number.</p>
  <p>My controller method is</p>
  <pre class="lang-java prettyprint-override"><code>@GetMapping(&quot;/users/{phone}&quot;)
  public List&lt;User&gt; getUserByPhone(@PathVariable int phone) {
     List&lt;User&gt; users= userService.findByPhone(phone);
     if(users == null) {
          throw new RuntimeException(&quot;User not found with &quot;+phone+&quot; phone number&quot;);
      }
      return users;
  }
  </code></pre>
  <p>And my DAO is</p>
  <pre class="lang-java prettyprint-override"><code>@Override
  @Transactional
  public List&lt;User&gt; findByPhone(int phone) {
      Session currentSession = entityManager.unwrap(Session.class);
      Query&lt;User&gt; theQuery = currentSession.createQuery(&quot;from User where phone=:phone&quot;,User.class);
      List&lt;User&gt; users = theQuery.getResultList();
          
      return users;
  }
  </code></pre>