title: How to Count the rows in Hibernate Query Language?
body: <p>I am trying to get just the count of the rows returned rather than all the results from the table.</p>
  
  <p>I saw that this can be done like this:</p>
  
  <pre><code>( (Integer) session.createQuery("select count(*) from ....").iterate().next() ).intValue()
  </code></pre>
  
  <p>But when trying to store this query in an integer format(it says cannot convert from <code>Query to Integer</code>)</p>
  
  <p>I am using a dynamic query where the values will be mentioned below the query like this</p>
  
  <pre><code>theQuery = "select count(*) from THM as thm " + 
                  "join thm.TMC as tmc " +
                  "join tmc.TIMCC as timcc " +
                  "where thm.Qid = :Qid and thm.Cv = :Cv and timcc.Did = :Did and timcc.Cv= :Cv";
  
  Query query = session.createQuery(theQuery);
  query.setInteger("Qid", Integer.parseInt(Qid));
  query.setInteger("Did", Did);
  query.setInteger("Cv",cV);
  </code></pre>
  
  <p>Now, how can i get a count of all the rows returned by using Hibernate query in a variable without using <code>list.size</code> but directly from the query?</p>