Hibernate count rows with some criterias

后端 未结 6 972
生来不讨喜
生来不讨喜 2021-02-07 15:16

Suppose I have a table Person and i want to count all those people whose \"birthDate\" is not null and they are a student. Assuming i have two columns :

birthDat         


        
6条回答
  •  余生分开走
    2021-02-07 15:41

    Use it. It's working

    public class IncIncidentListGridModel
    {
    
        private String historyStatus = null;
    
        public String getHistoryStatus()
        {
            return historyStatus;
        }
    
        public void setHistoryStatus(String historyStatus)
        {
            this.historyStatus = historyStatus;
        }
    
        public void run()
        {
            IncIncidentListGridModel resultCount =
                (IncIncidentListGridModel) ((SQLQuery) hibersession
                    .createSQLQuery("select count(ch.incident_capa_history_id) as historyStatus  from incident_capa_history ch, incident_capa ic where ic.incident_capa_id = ch.FK_incident_capa_id and ic.incident_capa_id='011'"))
                    .addScalar("historyStatus", Hibernate.STRING)
                    .setResultTransformer(
                        Transformers.aliasToBean(IncIncidentListGridModel.class))
                    .uniqueResult();
    
            System.out.println("count result" + resultCount.getHistoryStatus());
        }
    }
    

提交回复
热议问题