困扰很久了, 不知道什么原因
使每天早上打开页面系统就会提示类似
The last packet successfully received from the server was86395 milliseconds ago.The last packet sent successfully to the server was 86395 milliseconds ago或者提示
java.sql.SQLException: Operation not allowed after ResultSet closed
hibernate 配置文件如下:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">
jdbc:mysql://mysql:3306/mydb
</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="connection.autocommit">true</property>
<property name="hibernate.connection.useUnicode">true</property>
<property name="hibernate.connection.characterEncoding">UTF-8</property>
<property name="hibernate.show_sql">true</property> <!-- c3p0在我们使用的Hibernate版本中自带,不用下载,直接使用 -->
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.idle_test_period">900</property>
<property name="hibernate.c3p0.preferredTestQuery">select 1</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.testConnectionOnCheckout">true</property>
<!-- 以下就全是mapping了,省略 -->
</session-factory></hibernate-configuration>检查了下代码,没有直接关闭session之类的操作
请问各位,到底那里可能出问题啊?
使每天早上打开页面系统就会提示类似
The last packet successfully received from the server was86395 milliseconds ago.The last packet sent successfully to the server was 86395 milliseconds ago或者提示
java.sql.SQLException: Operation not allowed after ResultSet closed
hibernate 配置文件如下:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">
jdbc:mysql://mysql:3306/mydb
</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="connection.autocommit">true</property>
<property name="hibernate.connection.useUnicode">true</property>
<property name="hibernate.connection.characterEncoding">UTF-8</property>
<property name="hibernate.show_sql">true</property> <!-- c3p0在我们使用的Hibernate版本中自带,不用下载,直接使用 -->
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.idle_test_period">900</property>
<property name="hibernate.c3p0.preferredTestQuery">select 1</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.testConnectionOnCheckout">true</property>
<!-- 以下就全是mapping了,省略 -->
</session-factory></hibernate-configuration>检查了下代码,没有直接关闭session之类的操作
请问各位,到底那里可能出问题啊?
这个设置是生效的,每900秒hibernate就会使用select 1语句查询数据库,以保持连接所以就很奇怪什么原因了
java.sql.SQLException: Operation not allowed after ResultSet closed
第一个错误是在释放连接后,第一次执行时报的错;以后每次操作就会提示你的第二个错误.
你的程序里是不是有定时任务?定时任务间隔时间太长了,超过数据库空闲时间了,连接关闭造成的错误.
把你的wait timeout时间设置长一点.
程序真正执行过程中用到的是616,而616在使用后根本没有被刷新过,所以8小时后,必然就超时了这里使用hibernate有什么要求吗?
或者说session每次使用过以后需要什么特殊操作吗?130108 17:28:29 613 Query select 1
612 Query select 1
614 Query select 1
130108 17:28:34 613 Query select 1
614 Query select 1
612 Query select 1
130108 17:28:39 613 Query select 1
614 Query select 1
612 Query select 1
130108 17:28:44 612 Query select 1
614 Query select 1
613 Query select 1
130108 17:28:49 614 Query select 1
613 Query select 1
612 Query select 1
130108 17:28:54 613 Query select 1
612 Query select 1
614 Query select 1
130108 17:28:59 613 Query select 1
614 Query select 1
612 Query select 1
130108 17:29:04 614 Query select 1
613 Query select 1
612 Query select 1
130108 17:29:09 613 Query select 1
612 Query select 1
614 Query select 1
130108 17:29:14 614 Query select 1
613 Query select 1
612 Query select 1
130108 17:29:19 614 Query select 1
613 Query select 1
612 Query select 1
130108 17:29:21 616 Query select user0_.id as id61_, user0_.created_on as created2_61_, user0_.disable as disable61_, user0_.password as password61_, user0_.updated_on as updated5_61_, user0_.user_type as user6_61_, user0_.username as username61_ from health_center.user user0_ where user0_.username='11'
130108 17:29:24 614 Query select 1
612 Query select 1
613 Query select 1
130108 17:29:26 616 Query select user0_.id as id61_, user0_.created_on as created2_61_, user0_.disable as disable61_, user0_.password as password61_, user0_.updated_on as updated5_61_, user0_.user_type as user6_61_, user0_.username as username61_ from health_center.user user0_ where user0_.username='11'
130108 17:29:29 614 Query select 1
612 Query select 1
613 Query select 1
130108 17:29:34 613 Query select 1
614 Query select 1
612 Query select 1
130108 17:29:39 614 Query select 1
613 Query select 1
612 Query select 1
130108 17:29:44 614 Query select 1
612 Query select 1
613 Query select 1
130108 17:29:49 614 Query select 1
612 Query select 1
613 Query select 1
130108 17:29:54 613 Query select 1
614 Query select 1
612 Query select 1
130108 17:29:59 614 Query select 1
613 Query select 1
612 Query select 1
130108 17:30:04 613 Query select 1
612 Query select 1
614 Query select 1
实际证明,session使用完要close,然后这连接就会被返还给连接池了只是每次操作完成都要手工close session还是有点问题啊。
还有值得一提的是,异常特别提示了是ResultSet被关闭,我觉得这一点很重要,他既然特别提到了是ResultSet,那就很可能与Connection关闭无关,否则就应该提示Connection closed了,而日志记录中貌似也体现出了连接正常的信息,为了确认,对比一下时间(最后一次成功执行select 1的时间和异常发生后最后一次收发包的时间)。
130108 17:30:04 613 Query select 1
612 Query select 1
614 Query select 1
hibernate.connection.pool_size 5
hibernate.c3p0.min_size 50
hibernate.c3p0.max_size 800
hibernate.c3p0.max_statements 50
hibernate.jdbc.batch_size 10
hibernate.c3p0.timeout 300
hibernate.c3p0.idle_test_period 3000
hibernate.c3p0.testConnectionOnCheckout true这是hibernate官网推荐的配置。