首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

hibernate sum函数 返回Long 有关问题

2012-08-11 
hibernate sum函数 返回Long 问题hibernate sum函数求总和 得到的 使用query.uniqueResult()方法得到是一

hibernate sum函数 返回Long 问题
hibernate sum函数求总和 得到的 使用query.uniqueResult()方法得到是一个Long 但是我action里面需要一个int
我该怎么做 我的方法如下 但是不知道这样有没有什么潜在的问题?
求高人指教:
Action:
  int already_input_sum=storeService.get_can_input_sum_tounumber(plancode);
service:
  public int get_can_input_sum_tounumber(String plancode) {
Long l= storeDao.get_can_input_sum_tounumber(plancode);
int i=0;
long ll=l;
if(l!=null){
i=(int)ll;  
}
return i;
  }
Dao :
  public Long get_can_input_sum_tounumber(String plancode) {
String hql="select sum(tounumber) from InStoreInfo where plancode=? and inuse=0 and  
  plantype=2 and isAgree in(-1,1)";
Query query=sf.getCurrentSession().createQuery(hql);
query.setParameter(0, plancode);
Long l=(Long) query.uniqueResult();
return l;
}


[解决办法]
强制转换返回Long的父类Number,然后转为int类型
[解决办法]
直接调Long 的 intValue()方法啊
[解决办法]
public int get_can_input_sum_tounumber(String plancode) {
Long l= storeDao.get_can_input_sum_tounumber(plancode);
return l ==null ?0 : l.intValue();

热点排行