Could not open Hibernate Session for transaction . or java.net.SocketException: Broken pipe
2011-12-15 15:57
246 查看
Could not open Hibernate Session for transaction
最近做一个项目,布暑后出现"Could not open Hibernate Session for transaction",大意是数据库连接超时,需要设置重连.在这里转一个网上找的解决方案: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>
上文转自:/article/10024708.html
解决java.net.SocketException: Broken pipe异常
出现如下异常 解决的方式加上粗体到URL jdbc:mysql://localhost:3306/mydatabase? autoReconnect=true %26amp;amp; useUnicode=true%26amp;amp;characterEncoding=gb2312 Last packet sent to the server was 1 ms ago. STACKTRACE: com
出现如下异常
解决的方式加上粗体到URL
jdbc:mysql://localhost:3306/mydatabase?autoReconnect=true%26amp;amp;
useUnicode=true%26amp;amp;characterEncoding=gb2312
Last packet sent to the server was 1 ms ago. STACKTRACE: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** java.net.SocketException MESSAGE: Broken pipe STACKTRACE: java.net.SocketException: Broken pipe at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92) at java.net.SocketOutputStream.write(SocketOutputStream.java:136) at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65) at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123) at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2692) at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2621) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1552) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666) at com.mysql.jdbc.Connection.execSQL(Connection.java:2994) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:936) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1030) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139) at org.hibernate.loader.Loader.getResultSet(Loader.java:1669) at org.hibernate.loader.Loader.doQuery(Loader.java:662) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224) at org.hibernate.loader.Loader.loadEntity(Loader.java:1785)
项目中:/etc/my.cnf中增加:wait_timeout=864000
上文转自:http://sumdwang.blog.163.com/blog/static/79296950200911162150831/
相关文章推荐
- 解决Could not open Hibernate Session for transaction; nested exception is java.lang.NoClassDefFoundEr
- Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionExce
- Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionExcep
- Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionExcep
- could not open hibernate session for transaction; nested exception is org.hibernate.exception.generi
- Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionExcep
- Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: socket creation error
- Could not open Hibernate Session for transaction; nested exception is.....远程服务器部署后出现这个问题分析
- HTTP Status 500 - Could not open Hibernate Session for transaction; nested exception is org.hibernat
- Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.Generi
- Could not open Hibernate Session for transaction
- Could not open Hibernate Session for transaction 解决方案
- 解决Could not open Hibernate Session for transaction问题
- 解决Could not open Hibernate Session for transaction问题
- HTTP Status 500 - Could not open Hibernate Session for transaction;
- org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session
- Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: Connectio
- org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session
- org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session f
- Could not open Hibernate Session for transaction, 数据库连接超时解决方法