最近做一个项目,布暑后出现"Could not open Hibernate Session for transaction",大意是数据库连接超时,需要设置重连.在这里转一个网上找的解决方案:
spring2.x+hibernate3+struts2 在首次登陆系统时抛出的异常,再登陆就正常。
异常:
javax.servlet.ServletException: org.springframework.transaction.CannotCreateTransactionE
root cause
org.springframework.transaction.CannotCreateTransactionE
解决方案:
1.
给jdbc url 增加 autoReconnect=true 一定能解决你的问题,可以定期观察一下 show processlist
改进方法如下:
<property name="url" value="jdbc:mysql://localhost/数据库实例名称?&useUnicode=true&characterEncoding=utf-8&autoReconnect=true"/>
2.
寻找支持重连的连接池。
在sessionFactory里配置:
<property name="hibernateProperties">
</property>