Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (10.2k points)

For example, if we have a table Books, how would we count total number of book records with hibernate?

1 Answer

0 votes
by (46k points)

For older transcriptions of Hibernate (<5.2):

Considering the class name is Book:

return (Number) session.createCriteria("Book")

                  .setProjection(Projections.rowCount())

                  .uniqueResult();

It is at least a Number, most likely a Long.

Browse Categories

...