0

I want to get the row count of 2 different values from the database.How i write the hibernate criteria query for that? For example, in my table contain a field named 'status' and its values are 0 and 1.How could i get how many 0 and how many 1 are in my table?

salna K
  • 203
  • 1
  • 7

1 Answers1

0

This will do

select count(status) from table group by status

Hibernate Criteria

List result = session.createCriteria(Table.class)       
                    .setProjection(Projections.projectionList()
                            .add(Projections.groupProperty("status"))
                            .add(Projections.count("status"))           
                    ).list();
Vinit Prajapati
  • 1,593
  • 1
  • 17
  • 29