0

I'm trying to fetch the count of all individual records from mysql database using hibernate and I have to store it in a map collection. How to do this?

try {
    SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
    session = sessionFactory.openSession();
    tx = session.beginTransaction();
    String hql = "select attendencestatus ,COUNT(attendencestatus) from studentattendance group by attendencestatus ";
    Query query = session.createQuery(hql);     
    tx.commit();

} catch (HibernateException he) {
    he.printStackTrace();
    tx.rollback();
}
Lahiru
  • 1,428
  • 13
  • 17
srinivas gowda
  • 486
  • 5
  • 23
  • isn't [this post](http://stackoverflow.com/questions/1372317/how-do-we-count-rows-using-hibernate) helpful? or may be [this](http://stackoverflow.com/questions/18484988/hibernate-criteria-return-page-and-rowcount)? – StackUseR Jan 06 '17 at 10:01

1 Answers1

1
--------------------------------------
|   ID    |CountryName|  CurrencyName|
|_________|___________|______________|
|   1     | India     |   Rupees     |
|   2     | India     |   Rupees     |
|   3     | India     |   Rupees     |
|   4     | Usa       |   dollar     |
|   5     | dubai     |   AED        |
|   6     | Germany   |   Euro       |
|--------------------------------------

String hql="select anyColmnName from entity;
 Query query = session.createQuery(hql);
 List<string> list=query.list();
int countOfRecords=Collections.frequency(list, value)

Example

  String hql="select  countryName from Revenue;
     Query query = session.createQuery(hql);
     List<string> list=query.list();
    int countOfRecords=Collections.frequency(list, "India")
srinivas gowda
  • 486
  • 5
  • 23