zoukankan      html  css  js  c++  java
  • Could not obtain transaction-synchronized Session for current thread 错误的解决方法!

     1         BsTable bsTable = new BsTable();
     2 
     3 //        String time = request.getParameter("date");
     4         String time = Constant.getStringDate(0);
     5         
     6         Map<String, String> map = new HashMap<String, String>();
     7         map.put("attendanceDate", time);
     8         
     9         params.clear();
    10         params.putAll(map);
    11         
    12         StringBuilder strSQL = new StringBuilder("SELECT apply_user_name 'name', ");
    13         strSQL.append(" count(CASE WHEN type='1' THEN type END) 'field1', ");                //迟到
    14         strSQL.append(" count(CASE WHEN type='3' THEN type END) 'field3', ");                //未签到
    15         strSQL.append(" count(CASE WHEN type='4' THEN type END) 'field4', ");                //请假
    16         strSQL.append(" count(CASE WHEN type='5' THEN type END) 'field5', ");                //外出
    17         strSQL.append(" count(CASE WHEN leave_type='病假' THEN leave_type END) 'field10',");    //病假
    18         strSQL.append(" count(CASE WHEN leave_type='事假' THEN type END) 'field11' ");        //事假
    19         strSQL.append(" FROM t_sign_record_late ");
    20         strSQL.append(" WHERE attendance_date=:attendanceDate");
    21         strSQL.append(" GROUP BY apply_user_name ");
    22 
    23         List report_list = signRecordReportDao.findBySql(strSQL.toString(), params);
    24         
    25         String strSQL_count = "SELECT COUNT(*) FROM (" + strSQL.toString() + ") t";
    26         bsTable.setTotal(signRecordReportDao.countBySql(strSQL_count).longValue());
    27         bsTable.setRows(report_list);
    28         
    29     
    30         return bsTable;

    SpringMVC + Hibernate,使用事务管理 Service 层。但是这段代码放在 controller 里面就会遇到错误!

    解决方法就是把数据库的相关操作放在 Service 层,用事务来管理就不会出错了

  • 相关阅读:
    h5红包雨
    Reflect
    el-dialog对话弹框中根据后台数据无限制添加el-select标签,并进行展示,搜索,删除
    jQuery伪分页效果
    canvas实现验证码
    jQuery四叶草菜单效果,跟360杀毒软件差不多
    事件
    传参
    在shell script中进行数值运算的两种方法
    为maven插件设置参数的三种方法
  • 原文地址:https://www.cnblogs.com/jarod99/p/7410001.html
Copyright © 2011-2022 走看看