hibernate统计过万的记录

丰富的分地方的 2009-10-22 05:36:07
比如select count(*) from user;
那么用query.list().hashCode()返回的是什么?

我只想得到count(*),应该怎么得?
...全文
122 17 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
BearKin 2009-10-23
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 gyl05414 的回复:]
引用 8 楼 apollo_ts 的回复:
(BigInteger)强行转换

这证明你的数据库中本来就是大字段。

我数据库是int的
[/Quote]

跟你数据库没关系 你查询出来的count是BigInteger的(谁知道记录总数会有多少条呢..) 虽然可能不会那么长 但是就那么用吧
APOLLO_TS 2009-10-23
  • 打赏
  • 举报
回复
很简单的一个道理,你要收集黄豆,但是你要有比黄豆大的多的容器才能收集。
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 apollo_ts 的回复:]
引用 11 楼 gyl05414 的回复:
引用 8 楼 apollo_ts 的回复:
(BigInteger)强行转换

这证明你的数据库中本来就是大字段。

我数据库是int的


你自己看吧int(11)估计!!

public static final String FROM = "from";
public static final String SELECT_PREFIX = "select count(*) ";

public String getCountQuery(String hql){
int index = hql.indexOf(FROM);
if(index != -1){
return SELECT_PREFIX + hql.substring(index);
}
throw new ESBException(ConstantZhCnStr.COMBINE_ERROR,"COMMON.COMBINE.ERROR");
}
[/Quote]

是11额,那怎么改就不会报java.math.BigInteger ?
APOLLO_TS 2009-10-23
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 gyl05414 的回复:]
引用 8 楼 apollo_ts 的回复:
(BigInteger)强行转换

这证明你的数据库中本来就是大字段。

我数据库是int的
[/Quote]

你自己看吧int(11)估计!!

public static final String FROM = "from";
public static final String SELECT_PREFIX = "select count(*) ";

public String getCountQuery(String hql){
int index = hql.indexOf(FROM);
if(index != -1){
return SELECT_PREFIX + hql.substring(index);
}
throw new ESBException(ConstantZhCnStr.COMBINE_ERROR,"COMMON.COMBINE.ERROR");
}
lovenl058 2009-10-23
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 apollo_ts 的回复:]
String countHql = getCountQuery(hql);
Query query = getSession().createQuery(countHql);
int total = ((Long)query.uniqueResult()).intValue();
[/Quote]



支持
lovezx1028 2009-10-23
  • 打赏
  • 举报
回复


Query query = getSession().createQuery("select count(*) from user");
int total = ((Long)query.uniqueResult()).intValue();
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 apollo_ts 的回复:]
(BigInteger)强行转换

这证明你的数据库中本来就是大字段。
[/Quote]
我数据库是int的
jwtigerqwe 2009-10-23
  • 打赏
  • 举报
回复
同上
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 apollo_ts 的回复:]
String countHql = getCountQuery(hql);
Query query = getSession().createQuery(countHql);
int total = ((Long)query.uniqueResult()).intValue();
[/Quote]
String countHql = getCountQuery(hql); 这局是什么额?
APOLLO_TS 2009-10-23
  • 打赏
  • 举报
回复
(BigInteger)强行转换

这证明你的数据库中本来就是大字段。
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zl3450341 的回复:]
Java code//统计集团总人数public Integer payoffManSum()throws Exception{
Query q=hibernateSession.createQuery("select count(f.fileInfoId) from FileInfo f where f.fileState=1");
List payoffList¡­
[/Quote]

为什么我会报java.math.BigInteger
错误?
shihuaxian123 2009-10-23
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 apollo_ts 的回复:]
String countHql = getCountQuery(hql);
Query query = getSession().createQuery(countHql);
int total = ((Long)query.uniqueResult()).intValue();
[/Quote]这样的话,好像只用于框架
茂茂她爸 2009-10-23
  • 打赏
  • 举报
回复
新手过来看看
v05120s 2009-10-23
  • 打赏
  • 举报
回复
坚持3楼,顶一下
APOLLO_TS 2009-10-23
  • 打赏
  • 举报
回复
String countHql = getCountQuery(hql);
Query query = getSession().createQuery(countHql);
int total = ((Long)query.uniqueResult()).intValue();
老张-AI 2009-10-22
  • 打赏
  • 举报
回复

//统计集团总人数
public Integer payoffManSum() throws Exception{
Query q=hibernateSession.createQuery("select count(f.fileInfoId) from FileInfo f where f.fileState=1");
List payoffList=q.list();
return (Integer)payoffList.get(0);

}
xiaozejun 2009-10-22
  • 打赏
  • 举报
回复
就是用你的sql语句 获得一个list 在获得list的第一项 就行了啊

67,550

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧