spring2.x+hibernate3+struts2 在首次登陆系统时抛出的异常,再登陆就正常。
异常:
javax.servlet.ServletException: org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC begin failed:
root cause
org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC begin failed:
解决方案:
1.
给jdbc url 增加 autoReconnect=true 一定能解决你的问题,可以定期观察一下 show processlist
改进方法如下:
<property name="url" value="jdbc:mysql://localhost/数据库实例名称?&useUnicode=true&characterEncoding=utf-8&autoReconnect=true"/>
2.
寻找支持重连的连接池。
注意:c3p0连接池支持重连;重连参数是:
idleConnectionTestPeriod 设置空闲连接测试周期
preferredTestQuery : 设置一查询语句,用于重连测试
testConnectionOnCheckin设置为true
testConnectionOnCheckout设置为true
在sessionFactory里配置:
<property name="hibernateProperties">
<props>
<prop key="hibernate.autoReconnect">true</prop>
</props>
</property>
分享到:
相关推荐
Could not roll back Hibernate transaction.doc
可以对hibernate的 Session 和 Transaction 有更深入的认识 希望对一些概念比较模糊的人 有帮助
NULL 博文链接:https://stewchicken.iteye.com/blog/938875
org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot get a ...
介绍Hibernate+Transaction+myeclipse6+事例的应用参考工程源码.
spring-hibernate-maven-transaction整合
Transaction tx1 = session1.beginTransaction(); // 先加载一个持久化对象 Customer customer = (Customer)session.get(Customer.class, new Long(1)); session.delete(customer); // 计划执行一个delete语句
Beginning Hibernate is ideal if you’re experienced in Java with databases (the traditional, or connected, approach), but new to open-source, lightweight Hibernate. The book keeps its focus on ...
Beginning Hibernate is ideal if you’re experienced in Java with databases (the traditional, or connected, approach), but new to open-source, lightweight Hibernate. The book keeps its focus on ...
hibernate概述,hibernate入门Demo,hibernate配置文件详解(全局配置,实体类映射配置),配置实体规则,核心API详解(Configuration,sessionFactory,session,Transaction),hibernate中的对象状态以及刷新能缓存机制 ...
PureDataSystem for Transaction探析
此文档是X/OPEN DTP的TX规范,后续还会有XA规范上传。
Hibernate的核心接口一共有6个,分别为:Session、SessionFactory、Transaction、Query、Criteria和Configuration。这6个核心接口在任何开发中都会用到。通过这些接口,不仅可以对持久化对象进行存取,还能够进行事务...
## you do NOT need this setting if you specify hibernate.transaction.manager_lookup_class #jta.UserTransaction jta/usertransaction #jta.UserTransaction javax.transaction.UserTransaction #jta....
Hibernate Web应用的开发一般经过以下几个步骤: (1)创建数据库。 (2)将Hibernate所需的JAR包复制到WEB-INF/lib下。 (3)创建Hibernate的配置文件。 (4)利用Hibernate的第三方工具或Eclipse的有关插件从...
eclipse安装Activiti Designer 5.14.1插件失败后,把这上述压缩包中的jar文件拷贝到自己的eclipse的plugin文件夹下面,重启eclipse再次安装activiti插件就可以了。
具体报错如下: Cannot complete the install because one or more required items could not be found. Software being installed: Activiti Eclipse BPMN 2.0 Designer 5.18.0.201508100929 (org.activiti....
Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,使得Java...Hibernate的核心接口一共有6个,分别为:Session、SessionFactory、Transaction、Query、Criteria和Configuration。
Beginning Hibernate, Third Edition is ideal if you’re experienced in Java with databases (the traditional, or «connected,» approach), but new to open-source, lightweight Hibernate, a leading object...
Session对象.beginTransaction().begin(); //开始一个事务 4.用Session对象的以下方法操作数据 (1).save(Object obj); (2).saveOrUpdate(Object obj); (3).delete(Object obj); //只要删除的对象设置了主键的值...