基于Hibernate的Java Servlet应用程序中的Hibernate通信链接失败 [英] Hibernate Communications Link Failure in Hibernate Based Java Servlet application powered by MySQL

查看:99
本文介绍了基于Hibernate的Java Servlet应用程序中的Hibernate通信链接失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我描述一下我的问题 -

Let me describe my question -

我有一个Java应用程序 - Hibernate作为MySQL上的数据库接口层。我的应用程序中出现通信链接失败错误。这个错误的发生是一个非常特殊的情况。我得到这个错误,当我离开MySQL服务器无人看管的时间超过大约6个小时(即,当没有向MySQL发出超过约6小时的查询时)。我在下面粘贴一个顶级例外级别描述,并为详细的堆栈跟踪描述添加一个pastebin链接。

I have a Java application - Hibernate as the DB interfacing layer over MySQL. I get the communications link failure error in my application. The occurence of this error is a very specific case. I get this error , When I leave mysql server unattended for more than approximately 6 hours (i.e. when there are no queries issued to MySQL for more than approximately 6 hours). I am pasting a top 'exception' level description below, and adding a pastebin link for a detailed stacktrace description.


javax.persistence.PersistenceException:
org.hibernate.exception.JDBCConnectionException:
无法打开连接
- 导致:org.hibernate.exception.JDBCConnectionException:
无法打开连接
- 导致:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
通信链接失败
- 从服务器成功收到的最后一个数据包是
1,274,868,181,212毫秒前。
最后一个数据包成功发送到
服务器是0毫秒前。
- 导致:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
通信链路故障
- 从服务器成功接收的最后一个数据包是
1,274,868,181,212毫秒前。
最后一个数据包成功发送到
服务器是0毫秒前。
- 导致:java.net.ConnectException:连接
被拒绝:connect

连接到pastebin进一步调查 - http://pastebin.com/4KujAmgD

the link to the pastebin for further investigation - http://pastebin.com/4KujAmgD

我从这些异常声明中了解到,MySQL在一段闲置/零活动期间拒绝接受任何连接。我一直在通过谷歌搜索阅读这篇文章,并且知道解决这个问题的可能方法之一是为c3p0属性设置值,因为c3p0与Hibernate捆绑在一起。具体来说,我从这里阅读 http://www.mchange.com/projects/c3p0/ index.html ,设置两个属性idleConnectionTestPeriod和preferredTestQuery将为我解决这个问题。但是,这些价值似乎没有效果。

What I understand from these exception statements is that MySQL is refusing to take in any connections after a period of idle/nil activity. I have been reading up a bit about this via google search, and came to know that one of the possible ways to overcome this is to set values for c3p0 properties as c3p0 comes bundled with Hibernate. Specifically, I read from here http://www.mchange.com/projects/c3p0/index.html that setting two properties idleConnectionTestPeriod and preferredTestQuery will solve this for me. But these values dont seem to have had an effect.

这是解决这个问题的正确方法吗?如果不是的话,什么是正确的方法来克服这个问题?

Is this the correct approach to fixing this? If not, what is the right way to get over this?

以下是相关的通信链接失败问题在stackoverflow.com,但我还没有找到一个满意的答案在他们的答案中。
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败
如何处理:通信链路故障

The following are related Communications Link Failure questions at stackoverflow.com, but I've not found a satisfactory answer in their answers. com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:Communications link failure How to handle: Communication link failure

注意1 - 当我连续使用我的应用程序时,我没有得到这个错误。
注2 - 我在Hibernate中使用JPA,因此我的hibernate.dialect等hibernate属性驻留在META-INF文件夹的persistence.xml中(这是否会阻止c3p0属性正常工作?)。

Note 1 - i dont get this error when I am using my application continuosly. Note 2 - I use JPA with Hibernate and hence my hibernate.dialect,etc hibernate properties reside within the persistence.xml in the META-INF folder (does that prevent the c3p0 properties from working?)

edit -
我试过的c3p0参数在注释中

edit - the c3p0 parameters I tried out are in the comments

推荐答案

我之前有问题。它看起来像MySQL服务器超时你的连接。
超时默认为28800,即8小时。请参阅此链接了解更多详情。

I had issue before. It looks like MySQL server times out your connection. Timeout is 28800 by default which is 8 hours. Please refer to this link for more details.

http://shengchien.blogspot.com/2009/10/hibernate-c3p0-and-mysql.html

希望它对你有用。

这篇关于基于Hibernate的Java Servlet应用程序中的Hibernate通信链接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆