Hibernate Group by Criteria Object

前端 未结 4 796
一整个雨季
一整个雨季 2020-11-29 02:42

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

SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_n         


        
4条回答
  •  迷失自我
    2020-11-29 03:33

    If you have to do group by using hibernate criteria use projections.groupPropery like the following,

    @Autowired
    private SessionFactory sessionFactory;
    Criteria crit = sessionFactory.getCurrentSession().createCriteria(studentModel.class);
    crit.setProjection(Projections.projectionList()
                .add(Projections.groupProperty("studentName").as("name"))
    List result = crit.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP).list(); 
    return result;  
    

提交回复
热议问题