title: org.hibernate.NonUniqueResultException: query did not return a unique result: 2?
body: <p>I have below code in my DAO:</p>
  <pre><code>String sql = &quot;SELECT COUNT(*) FROM CustomerData &quot; +
               &quot;WHERE custId = :custId AND deptId = :deptId&quot;;
  Query query = session.createQuery(sql);
  query.setParameter(&quot;custId&quot;, custId);
  query.setParameter(&quot;deptId&quot;, deptId);
  long count = (long) query.uniqueResult(); // ERROR THROWN HERE
  </code></pre>
  <p>Hibernate throws  below exception at the marked line:</p>
  <blockquote>
  <p>org.hibernate.NonUniqueResultException: query did not return a unique result:</p>
  </blockquote>
  <p>I am not sure whats happening as <code>count(*)</code> will always return only one row.</p>
  <p>Also when i run this query on db directly, it return result as 1. So whats the issue?</p>