Count all rows of a table
Hibernate request to count table rows:
int paginationSize = 10; int pages = 0; float countCities = 0; List countCitiesList = hs.createSQLQuery("SELECT count(id) AS count FROM cities") .addScalar("count", Hibernate.INTEGER) .list(); if (!countCitiesList.isEmpty()) { Iterator tmp_iter = countCitiesList.iterator(); while (tmp_iter.hasNext()) { Integer tmp_ii = (Integer)tmp_iter.next(); countCities = tmp_ii.floatValue(); } } pages = Math.round( countCities / paginationSize ); |
Follow Us!