0
Query query = session.createSQLQuery(
"SELECT ColumnName, COUNT(*) FROM xyz GROUP BY ColumnName")
.addEntity(xyz.class);
return query.list();

但它在会话时向我显示错误(会话无法解决)如果有人可以帮助我执行此查询,我将不胜感激。

提前致谢

4

1 回答 1

0

看来您的 Session 对象未声明。

还要检查导入:

import org.hibernate.cfg.Configuration;
import org.hibernate.SessionFactory;
import org.hibernate.Session;

典型的休眠会话代码:

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

Session session = sessionFactory.openSession();

然后使用您的代码:

Query query = session.createSQLQuery(
"SELECT ColumnName, COUNT(*) FROM xyz GROUP BY ColumnName")
.addEntity(xyz.class);
return query.list();
于 2013-02-12T10:27:18.080 回答