hibernate count
来源:互联网 发布:淘宝维护权人工电话 编辑:程序博客网 时间:2024/06/06 07:37
最近开始学习和更多的使用hibernate了,以前总是注重效率,就开发的用原始的jdbc,但是封装性不强,太多冗余代码,hibernate还是可以学习的,嘻嘻。
然后碰到涉及总数的计算,因为总有后面的条件判断等等,如果是原始sql的话,就是下面的了
sql = "select count(*) as num from (" + sql + ") ff";
然而总是hibernate报错了,有人说是Hibernate是不允计from后面出现(select xxxx from xxxx)这种语句的,没办法啊。。。
最终看到这样的方法,感觉还是可以滴
<pre name="code" class="html">int sql_index = query.indexOf("from");String countStr = "select count(*) "+query.substring(sql_index);; List l = getSession().createQuery(countStr).list();if (!l.isEmpty()) {num = ((Long)l.get(0)).intValue();}return num;
格式真难调。。。啊,记录一下。
0 0
- hibernate count
- Hibernate 如何使用count(*)
- Hibernate 如何使用count(*)
- hibernate count(*) 查询
- Hibernate(select count(*))
- Hibernate 如何使用count(*)
- Hibernate 如何使用count(*)
- Hibernate count映射问题
- hibernate:count查询
- spring + hibernate 如何使用count(*)
- Hibernate 使用 count(*)、avg、sum
- hibernate 数据行数统计 count(*)
- Hibernate中使用COUNT DISTINCT
- Hibernate count和sum查询
- Hibernate 解决SQL count(*)的问题.
- Hibernate中的count是Integer还是Long?
- hibernate 中的count和distinct同时使用
- hibernate QBC count查询(投影)
- jquery ul li 遍历案例
- MyEclipse 8.5 新安装时不能使用提示的问题
- c++ 类的继承与派生
- Log4j文件日志性能瓶颈
- UTF8 、unicode 和 Ascii2
- hibernate count
- 忧桑T_T
- jquery 中 remove()在IE9有上传flash的东西时不起作用,不妨试 detach()
- C/C++语言extern使用方法总结
- C++虚函数与纯虚函数的区别
- 剑指Offer:二维数组中的查找
- 2-sat问题,输出方案,几种方法(赵爽的论文染色解法+其完全改进版)浅析 / POJ3683
- 关于浮点数的运算误差问题
- android bitmap 指定任何一个角为圆角 处理方法