title: How to verify existence of a record in database?
body: <p>I need to verify the existence of a record in database, but regardless of the id that I pass to the following code, it does not show anything. either the record exists or not.</p>
  
  <pre><code>       session = HibernateUtil.getSession();
          session.beginTransaction();
          Query q = session.createQuery("select count(*) from Users where id = :id");
          q.setInteger("id", id);
          Integer count = (Integer)q.uniqueResult();
          if(count &gt; 0) {
              System.err.println("&gt;");
          }
          else {
              System.err.println("&lt;");
          }
          session.getTransaction().commit();
          session.close();
  </code></pre>
  
  <p>I've used the following code as well but still have the same problem</p>
  
  <pre><code>  try{
          session = HibernateUtil.getSession();
          session.beginTransaction();
          Users users = null;
          users = (Users) session.load(Users.class, id);
      }catch(Exception e){
                System.err.println("&lt;");
        }
  </code></pre>