您的位置:首页 > 数据库 > MySQL

解决mysql LOCK TABLES 后事务无法回滚的问题

2017-02-24 18:07 393 查看
在spring mvc+ mybatis中定义了一个事务,事务是service 层的一个方法fun1如

try{

....
lock tables ...
}finally{
unlock tables...;
}


坑来了,这样会导致fun1不会回滚,解决是在Controller层来释放锁,即锁释放不能在fun1中释放,


public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse resp) throws Exception {
ModelAndView mav = new ModelAndView();
Result result = new Result();
try {
result = upListService.updataListGoodsEx(code,goodsNumStr,goodsIdStr,teamIdStr,goodsPriceStr,user.getStructId());
} catch (Exception e) {
result.setMsg(e.getMessage());
}finally {
sfm.unlockTable(null);
}

return CheckUtil.returnResult(mav, result.getCode(), result.getMsg()
, result.getData());
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: