本文介绍了我们如何使用旧版本的Hibernate(~2009)计算行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果我们有一个表Books,我们如何计算hibernate的书记录总数?

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

推荐答案

旧版本的Hibernate(< 5.2):

假设班级名称为Book:

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.

这篇关于我们如何使用旧版本的Hibernate(~2009)计算行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 04:53
查看更多