博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Could not open Hibernate Session for transaction, 数据库连接超时解决方法
阅读量:4519 次
发布时间:2019-06-08

本文共 1002 字,大约阅读时间需要 3 分钟。

  1. 异常:  
  2. javax.servlet.ServletException: org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC begin failed:   
  3.    
  4. root cause   
  5. org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC begin failed:   
  6.    
  7.    
  8. 解决方案:  
  9. 1.  
  10. 给jdbc url 增加 autoReconnect=true 一定能解决你的问题,可以定期观察一下 show processlist  
  11. 改进方法如下:  
  12. <property name="url" value="jdbc:mysql://localhost/数据库实例名  
  13. 称?&useUnicode=true&characterEncoding=utf-8&autoReconnect=true"/>  
  14.    
  15. 2.  
  16. 寻找支持重连的连接池。  
  17.            注意:c3p0连接池支持重连;重连参数是:  
  18.                idleConnectionTestPeriod   设置空闲连接测试周期  
  19.                preferredTestQuery : 设置一查询语句,用于重连测试  
  20.               testConnectionOnCheckin设置为true  
  21.               testConnectionOnCheckout设置为true  
  22.    
  23. 在sessionFactory里配置:  
  24. <property name="hibernateProperties">  
  25.    <props>  
  26.         <prop key="hibernate.autoReconnect">true</prop>   
  27.   </props>  
  28. </property>  

转载于:https://www.cnblogs.com/jianmang/articles/5604249.html

你可能感兴趣的文章
【翻译】西川善司「实验做出的游戏图形」「GUILTY GEAR Xrd -SIGN-」中实现的「纯卡通动画的实时3D图形」的秘密,前篇(2)...
查看>>
函数名、闭包及迭代器
查看>>
mysql 5.6 参数详解
查看>>
求旋转数组的最小元素
查看>>
jQuery ajax error函数(交互错误信息的获取)
查看>>
Gson解析Json数组
查看>>
Lintcode: Fast Power
查看>>
Pocket Gem OA: Log Parser
查看>>
枚举也能直接转换为对应的数值输出
查看>>
angularjs1-7,供应商
查看>>
BitSet
查看>>
Spring常用注解,自动扫描装配Bean
查看>>
(转载)深入理解WeakHashmap
查看>>
JAVA中的数组
查看>>
爬虫—使用Requests
查看>>
scrollIntoView()窗口滚动
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
使用ansible远程管理集群
查看>>
读jQuery源码释疑笔记3
查看>>
手把手教你jmeter压测--适合入门
查看>>