HOW to use HAVING COUNT(*) with hibernate

后端 未结 4 1854
面向向阳花
面向向阳花 2020-12-10 13:58

I need to create a query and I need COUNT(*) and HAVING COUNT(*) = x.

I\'m using a work around that uses the CustomProjection

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-10 14:41

    I figured out the problem. I replace CusotmProjections class, with:

    .add( Projections.sqlGroupProjection("ensayo_id", groupBy , alias, types));
    

    where groupBy, alias and types are:

     String groupBy = "ensayo_id" + " having " + "count(*) = " + String.valueOf(lineas.size());
     String[] alias = new String[1]; 
     Alias[0] = "ensayo_id"; 
     Type[] types = new Type[1]; 
     types[0] = Hibernate.INTEGER;
    

    and the magic is on groupby String. –

提交回复
热议问题