title: Hibernate simple select query doesn't return anything
body: <p>I got this simple Hibernate query set up but it returns nothing, here is my code:</p>
  
  <pre><code>      EntityManagerFactory emf = javax.persistence.Persistence.createEntityManagerFactory("timereg");
        EntityManager em = emf.createEntityManager();
  
       int id = em.createQuery("SELECT emp.id FROM Employee as emp WHERE emp.bsn = '398723916'").getFirstResult();
       object.getEmployee().setId(id);
       System.out.println("query returns employee id: " + id);
  </code></pre>
  
  <p>The stupid thing is that id stays zero but when i execute this query in PostgreSQL it returns 37.</p>
  
  <p>I think hibernate does not like my way of implementing a select query, does anyone know what is wrong with my select query ?</p>
  
  <p><strong>THE ANSWER:</strong>
  There was nothing wrong with the select query i just had to use getSingeResult() instead of getFirstResult();
  Change the code into:</p>
  
  <pre><code>EntityManagerFactory emf = javax.persistence.Persistence.createEntityManagerFactory("timereg");
        EntityManager em = emf.createEntityManager();
  
       Object ob = em.createQuery("select id from Employee where bsn = '398723917'").getSingleResult();
  
          object.getEmployee().setId(Integer.parseInt(ob.toString()));
          System.out.println(ob);
  </code></pre>
  
  <p>This is the total solution for my problem, but i got inspired by Yanflea so he deserves all the credits.</p>