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 层,用事务来管理就不会出错了
相关文章推荐
- Could not obtain transaction-synchronized Session for current thread解决方法
- Spring-hibernate开发时遇到 Could not obtain transaction-synchronized Session for current thread的问题解决
- 由Could not obtain transaction-synchronized Session for current thread错误处理引申到声明式与编程式事务处理
- 错误记录(九)Could not obtain transaction-synchronized Session for current thread
- spring+Hibernate5的Could not obtain transaction-synchronized Session for current thread解决
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- springmvc+spring4+hibernate4整合Could not obtain transaction-synchronized Session for current thread
- ssh整合 出现Could not obtain transaction-synchronized Session for current thread
- 解决异常:org. 8af0 hibernate.HibernateException: Could not obtain transaction-synchronized Session for current
- Could not obtain transaction-synchronized Session for current thread
- org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- 多线程出现HibernateException: Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread -无法获取当前线程的事务同步会话-解决方案
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Hibernate4 提示Could not obtain transaction-synchronized Session for current thread