For example, if we have a table Books, how would we count total number of book records with hibernate?
For older versions of Hibernate (<5.2):
Assuming the class name is Book:
return (Number) session.createCriteria("Book") .setProjection(Projections.rowCount()) .uniqueResult(); It is at least a Number, most likely a Long.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With