package roseindia.tutorial.hibernate; import java.util.Iterator; import java.util.List; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; public class HibernateHQLCountFunctions { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Session sess = null; int count = 0; try { SessionFactory fact = new Configuration().configure().buildSessionFactory(); sess = fact.openSession(); String SQL_QUERY = "select count(*)from Insurance insurance group by insurance.lngInsuranceId"; Query query = sess.createQuery(SQL_QUERY); for (Iterator it = query.iterate(); it.hasNext();) { it.next(); count++; } System.out.println("Total rows: " + count); sess.close(); } catch(Exception e){ System.out.println(e.getMessage()); } } }