我正在尝试使用hibernate从mysql数据库中获取所有单个记录的计数,我必须将其存储在地图集合中。怎么做?
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();
}
答案 0 :(得分: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)
示例强>
String hql="select countryName from Revenue;
Query query = session.createQuery(hql);
List<string> list=query.list();
int countOfRecords=Collections.frequency(list, "India")