Back
For example, if we have a table Books, how would we count total number of book records with hibernate?
For older transcriptions of Hibernate (<5.2):
Considering the class name is Book:
return (Number) session.createCriteria("Book") .setProjection(Projections.rowCount()) .uniqueResult();
return (Number) session.createCriteria("Book")
.setProjection(Projections.rowCount())
.uniqueResult();
It is at least a Number, most likely a Long.
31k questions
32.8k answers
501 comments
693 users