您的位置:首页 > 大数据 > 人工智能

Could not obtain transaction-synchronized Session for current thread 错误的解决方法!

2017-08-22 09:36 651 查看
BsTable bsTable = new BsTable();

//        String time = request.getParameter("date");
String time = Constant.getStringDate(0);

Map<String, String> map = new HashMap<String, String>();
map.put("attendanceDate", time);

params.clear();
params.putAll(map);

StringBuilder strSQL = new StringBuilder("SELECT apply_user_name 'name', ");
strSQL.append(" count(CASE WHEN type='1' THEN type END) 'field1', ");                //迟到
strSQL.append(" count(CASE WHEN type='3' THEN type END) 'field3', ");                //未签到
strSQL.append(" count(CASE WHEN type='4' THEN type END) 'field4', ");                //请假
strSQL.append(" count(CASE WHEN type='5' THEN type END) 'field5', ");                //外出
strSQL.append(" count(CASE WHEN leave_type='病假' THEN leave_type END) 'field10',");    //病假
strSQL.append(" count(CASE WHEN leave_type='事假' THEN type END) 'field11' ");        //事假
strSQL.append(" FROM t_sign_record_late ");
strSQL.append(" WHERE attendance_date=:attendanceDate");
strSQL.append(" GROUP BY apply_user_name ");

List report_list = signRecordReportDao.findBySql(strSQL.toString(), params);

String strSQL_count = "SELECT COUNT(*) FROM (" + strSQL.toString() + ") t";
bsTable.setTotal(signRecordReportDao.countBySql(strSQL_count).longValue());
bsTable.setRows(report_list);

return bsTable;


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

解决方法就是把数据库的相关操作放在 Service 层,用事务来管理就不会出错了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐