Hibernate 获得;无法执行查询";13小时不活动后出现错误

Hibernate 获得;无法执行查询";13小时不活动后出现错误,hibernate,openjpa,Hibernate,Openjpa,我有以下设置: JSP/Servlet=>表示层。 Hibernate和OpenJPA=>数据访问层 为了连接到数据库,我将配置信息添加到一个“persistence.xml”文件中。以下是“persistence.xml”文件的条目: org.hibernate.connection.C3P0ConnectionProvider 我得到org.hibernate.exception.jdbconnectionexception:无法执行查询错误。13小时或更长时间不活动后。这一错误不会一直

我有以下设置: JSP/Servlet=>表示层。 Hibernate和OpenJPA=>数据访问层

为了连接到数据库,我将配置信息添加到一个“persistence.xml”文件中。以下是“persistence.xml”文件的条目:


org.hibernate.connection.C3P0ConnectionProvider
我得到
org.hibernate.exception.jdbconnectionexception:无法执行查询
错误。13小时或更长时间不活动后。这一错误不会一直重复。我无法在测试设置中重现该错误,但该错误将出现在生产服务器上

我已经搜索了论坛,有一些条目与我的相似,但它们没有回答我的问题。链接如下:


我是否缺少某些设置或做错了什么?

对我来说,这是c3p0版本问题。在使用最新的c3p0版本时,未发现问题。当抛出异常时,也会发生一些连接泄漏。在finally block worked中添加连接释放代码。

为什么要为这个问题标记OpenJPA?您正在执行的查询是什么?在生产环境中运行时,查询返回了多少数据?
@Rick
我在登录应用程序时遇到此错误。我正在执行的查询是
SELECT*from user,其中userid=x和password=xxx
此查询只返回一条记录。这是在OpenJPA中发生的,还是在Hibernate中发生的?您能够执行任何其他查询吗?因为这是第一个登录到系统的查询,所以我没有检查是否执行了任何其他查询。但当我尝试登录时,它成功了,因为有
?autoReconnect=true
参数
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.connection.url" value="jdbc:mysql://xxx.xxx.xxx.xxx:xxxx/test?autoReconnect=true"/>
<property name="hibernate.connection.username" value="xxx"/>
<property name="hibernate.connection.password" value="xxx"/>
<property name="hibernate.generate_statistics" value="true"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.OSCacheProvider"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.c3p0.min_size" value="5"/>
<property name="hibernate.c3p0.max_size" value="20"/>
<property name="hibernate.c3p0.timeout" value="1800"/>
<property name="hibernate.c3p0.max_statements" value="50"/>
<property name="hibernate.c3p0.idle_test_period" value="1800"/>
<property name="c3p0.idleConnectionTestPeriod" value="1810"/>