从SqlSession的实现类SqlSessionTemplate源码中,看出相关方法被其内部类SqlSessionInterceptor(实现了InvocationHandler)代理

当调用SqlSessionTemplate.getConnection()时,有SqlSessionInterceptor代理执行,从SqlSessionInterceptor源码中看到其invoke方法finally代码块那内容如:

//关闭SqlSession

导致获取到的Connection中delegate(委托)的holder(存放事务对象)为空

解决方案:

抽离代理,将代理方法SqlSessionInterceptor.invoke中的代码拿出直接使用

SqlSessionTemplate st = (SqlSessionTemplate) getSqlSession();

Connection connection = SqlSessionUtils.getSqlSession(
st.getSqlSessionFactory(), st.getExecutorType(),
st.getPersistenceExceptionTranslator()).getConnection();

这样获取到的Connection可以正常使用

最新文章

  1. Centos7的firewalld配置
  2. 【管理心得之四十】中文“其他”、英文“other”、日文“その他”..........................................
  3. ContentProvider详解
  4. 运行eclipse提示 The requested resource () is not available.
  5. 直接运行PowerShell脚本
  6. WCF架构日记-1
  7. flex学习网站地址
  8. cocos2d-x 2.2.3 之菜单分析(1)
  9. .Net_把文件数据添加到数据库中(面试题)
  10. sql/plus 常用操作
  11. (简单) POJ 3468 A Simple Problem with Integers , 线段树+区间更新。
  12. 用 Visual Studio Code 调试 Node.js
  13. Windows入门基础:2.vs2013中Icon显示
  14. 左耳听风-ARTS-第3周(2019/4/7-2019/4/13)
  15. react-native 报错 RawText "" must be wrapped in an explicit <Text> component
  16. jmeter获取cookies信息(配置)
  17. “此flash与您的地区不兼容”
  18. python 常见报错汇总
  19. 文件缓冲区在fork后复制
  20. 1085. Perfect Sequence

热门文章

  1. scala _ parameter
  2. 金融卡IC卡知识50问
  3. Monkey测试异常信息解读
  4. oracle数据库单表查询
  5. (转)Asp.Net生命周期系列三
  6. 编写高质量代码改善C#程序的157个建议——建议56:使用继承ISerializable接口更灵活地控制序列化过程
  7. XE ListBox实现伸缩效果
  8. Task async await
  9. Ubuntu 14.10,准备C/C++的编译环境
  10. python3好用的mysql.connector库