hibernate 分组查询

                  DetachedCriteria criteria = DetachedCriteria.forClass(DreamDownClient.class); /*实体类*/
                   /*参数1 查询的字段名,参数2 分组的字段,参数3 查询结果返回的列名,参数3,返回结果的字段类型*/
		criteria.setProjection( Projections.sqlGroupProjection("ditch,count(*) as c", "ditch", new String[]{ "ditch" , 
		"c"}, new Type[]{ IntegerType.INSTANCE  , IntegerType.INSTANCE } ) ) ;
		criteria.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP) ; 
		System.out.println( dreamDownClientServer.query( criteria ) ) ;

你可能感兴趣的:(hibernate 分组查询)