码迷,mamicode.com
首页 > 其他好文 > 详细

循环中不要放入openSession()

时间:2015-05-21 01:21:35      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

for(Shop s:list) {
            System.out.println(s.getName());
            String sql="select shopId,sum(ele_bank+ele_card+water_card+water_bank+coal_card+coal_bank) as zonghe ,sum(sale_bank+sale_card) as  sale,sum(cigarette_card+cigarette_bank)  as bacco, sum(yidong_card+yidong_bank+dianxin_card+dianxin_bank)  as recharge from hs_shop_items  where  record_time like ‘%2013-12-12%‘ and shopId="+s.getId();
            Session officeSession=officeSessionFactory.openSession();
            officeSession.beginTransaction();
            SQLQuery queryOffice=officeSession.createSQLQuery(sql);
            List<ShopTransDTO>  r=queryOffice.addEntity(ShopTransDTO.class).list();
            res.add(r.get(0));
        }

如上图中的

1
2
Session officeSession=officeSessionFactory.openSession();
            officeSession.beginTransaction();

这个部分放在循环中是错误的

循环中不要放入openSession()

标签:

原文地址:http://www.cnblogs.com/toSeeMyDream/p/4518604.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!