Hibernate Group by Criteria Object [英] Hibernate Group by Criteria Object

查看:95
本文介绍了Hibernate Group by Criteria Object的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  SELECT column_name,aggregate_function(column_name)$ b $ 

我想用Hibernate Criteria实现下面的SQL查询: b FROM table_name
WHERE column_name< operator>值
GROUP BY column_name

我试着用Hibernate Criteria实现它,但它没有' t出来。



任何人都可以给我一个例子,说明Hibernate Criteria可以做到这一点吗?
Thanks!

解决方案

请参考为例。主要观点是使用 groupProperty()以及由预测

提供的相关聚合函数, a> class。



例如:

  SELECT column_name,max(column_name),min(column_name),count(column_name)
FROM table_name
WHERE column_name> xxxxx
GROUP BY column_name

它的等价条件对象是:

 列表结果= session.createCriteria(SomeTable.class)
.add(Restrictions.ge(someColumn,xxxxx))
.proProjection(Projections.projectionList()
.add(Projections.groupProperty(someColumn))
.add(Projections.max(someColumn))
.add(Projections.min (someColumn))
.add(Projections.count(someColumn))
).list();


I would like to implement the following SQL query with Hibernate Criteria:

SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name <operator> value
GROUP BY column_name

I have tried to implement this with Hibernate Criteria but it didn't work out.

Can anyone give me an example how this can be done with Hibernate Criteria? Thanks!

解决方案

Please refer to this for the example .The main point is to use the groupProperty() , and the related aggregate functions provided by the Projections class.

For example :

SELECT column_name, max(column_name) , min (column_name) , count(column_name)
FROM table_name
WHERE column_name > xxxxx
GROUP BY column_name

Its equivalent criteria object is :

List result = session.createCriteria(SomeTable.class)       
                    .add(Restrictions.ge("someColumn", xxxxx))      
                    .setProjection(Projections.projectionList()
                            .add(Projections.groupProperty("someColumn"))
                            .add(Projections.max("someColumn"))
                            .add(Projections.min("someColumn"))
                            .add(Projections.count("someColumn"))           
                    ).list();

这篇关于Hibernate Group by Criteria Object的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆