【问题标题】:How to get the count of individual records from mysql using Hibernate如何使用 Hibernate 从 mysql 获取单个记录的计数
【发布时间】:2017-05-21 01:32:20
【问题描述】:

我正在尝试使用 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();
}

【问题讨论】:

标签: mysql hibernate


【解决方案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")

【讨论】:

    猜你喜欢
    • 2012-10-15
    • 2010-12-21
    • 2014-01-29
    • 2013-12-17
    • 2013-08-29
    • 2011-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多