ssm集成mybatis提交commit异常问题
来源:互联网 发布:java cs的前景 编辑:程序博客网 时间:2024/06/07 03:27
Manual commit is not allowed over a Spring managed SqlSession Manual close is not allowed over a Spring managed SqlSession
出现这种异常是因为spring在管理sqlsession对象的时候使用了代理类,通过这个代理类来实现对所有的事物实现提交以及关闭
跟踪源码我们可以发现
//这是我调用的方法,现在进入session的insert的方法内 public boolean insert(Users users) { SqlSession session = super.getSqlSession(); System.out.println(session); int insert = session.insert("com.cc.dao.UserDao.insert", users); return insert>0?true:false; }//发现原来是用代理类实现的,接着跟踪 public int insert(String statement, Object parameter) { return this.sqlSessionProxy.insert(statement, parameter); } //这是这个代理类的创建方式,于是,找到了SqlSessionInterceptor这个类 this.sqlSessionProxy = (SqlSession) newProxyInstance( SqlSessionFactory.class.getClassLoader(), new Class[] { SqlSession.class }, new SqlSessionInterceptor()); //这就是这个代理类的invoke方法,可以看到,他确实是帮我们实现了commit方法以及close方法 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { SqlSession sqlSession = getSqlSession( SqlSessionTemplate.this.sqlSessionFactory, SqlSessionTemplate.this.executorType, SqlSessionTemplate.this.exceptionTranslator); try { Object result = method.invoke(sqlSession, args); if (!isSqlSessionTransactional(sqlSession, SqlSessionTemplate.this.sqlSessionFactory)) { // force commit even on non-dirty sessions because some databases require // a commit/rollback before calling close() sqlSession.commit(true); } return result; } catch (Throwable t) { Throwable unwrapped = unwrapThrowable(t); if (SqlSessionTemplate.this.exceptionTranslator != null && unwrapped instanceof PersistenceException) { // release the connection to avoid a deadlock if the translator is no loaded. See issue #22 closeSqlSession(sqlSession, SqlSessionTemplate.this.sqlSessionFactory); sqlSession = null; Throwable translated = SqlSessionTemplate.this.exceptionTranslator.translateExceptionIfPossible((PersistenceException) unwrapped); if (translated != null) { unwrapped = translated; } } throw unwrapped; } finally { if (sqlSession != null) { closeSqlSession(sqlSession, SqlSessionTemplate.this.sqlSessionFactory); } } }
阅读全文
1 0
- ssm集成mybatis提交commit异常问题
- SSM项目集成mybatis-plus
- Could not commit Hibernate 异常问题,spring 事物 提交前session关闭问题
- ssm (spring,sprinMvc,mybatis)集成
- ssm(spring+springMVC+Mybatis)框架集成Mongodb
- 【SSM 8】spring集成Mybatis通用Mapper
- 最新spring,mybatis,springmvc(SSM)集成
- SSM框架集成(一)mybatis+spring
- 提交(Commit)
- springboot集成mybatis问题
- github_异常_特殊文件提交失败(Fail to commit)
- SSM + Shiro 整合 (2)- 实现 Spring 集成 MyBatis
- Struts2+Spring+Mybatis框架集成的搭建。(SSM形式)
- ssm(Spring+SpringMVC+Mybatis)框架集成Apache CXF2.7
- SSM框架集成整合(Spring+SpringMVC+mybatis)
- 分享一些ssm(springmvc+spring+mybatis)集成的demo
- SSM框架之--spring(二)spring集成mybatis
- MyBatis与Druid数据库连接池集成监控统计后WallFilterSQL注入异常问题处理方案
- uCOS/FreeRTOS任务创建的两种模式
- [SDS阅读理解/1]源码中的宏
- Stack和Heap的区别
- wustoj(二叉树根节点到指定结点的路径-非递归算法)
- 什么是人因工程?
- ssm集成mybatis提交commit异常问题
- vue的v_for
- 启明星第四周学习总结
- 前言
- Python 输出百分比的两种方式
- 八皇后问题
- mysql 查询某个字段不为空(附thinkphp写法)
- CodeForces 799B (B) T-shirt buying
- 正则表达式在线测试(生成)工具