简体   繁体   English

通讯链路故障ClearDB

[英]Communications Link Failure ClearDB

I realize that there are other questions similar to mine but I feel mine is a bit different so I'm going to ask it anyway. 我意识到还有其他与我类似的问题,但我觉得我的问题有所不同,所以我还是要问一下。 I've been using hibernate to develop a java web application and have run in to no problems when I run it on a localhost Tomcat server. 我一直在使用hibernate开发Java Web应用程序,并且在本地Tomcat服务器上运行它时也没有出现问题。 I've, however, been running into problems after trying to deploy it on Heroku and using the free version of ClearDB as the website would randomly throw an exception. 但是,在尝试将其部署到Heroku上并使用ClearDB的免费版本后,由于网站会随机抛出异常,因此我一直遇到问题。 Specifically, I am getting a 具体来说,我正在

org.hibernate.exception.JDBCConnectionException: Communications link failure 

Things I've found on google but believe to not be my issue: 我在Google上找到的东西,但相信不是我的问题:

  • Database was idle for too long ( > 8hours). 数据库空闲时间过长(> 8小时)。 I've been continuously using the website so it definitely has not been idle for longer than 8 hours. 我一直在使用该网站,因此它肯定没有闲置超过8个小时。
  • Too many connections to Database. 与数据库的连接过多。 I'm the only one currently connected to the database and the website says there is a maximum of 10 connections so I'm within their limit 我是当前连接到数据库的唯一一个,网站说最多有10个连接,所以我在其限制范围内

My configuration file 我的配置文件

<?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">
<hibernate-configuration>
<session-factory>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.password">PASSWORD</property>
    <property name="hibernate.connection.url">jdbc:mysql://DBURL?reconnect=true</property>
    <property name="hibernate.connection.username">USERNAME</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name= "hbm2ddl.auto">update</property>
    <property name="show_sql">true</property>
</session-factory>

Thanks in advance 提前致谢

I'd be willing to bet that this goes away if you use JawsDB add-on instead of ClearDB: 我敢打赌,如果您使用JawsDB附加组件而不是ClearDB,那么这将消失:

$ heroku addons:destroy cleardb
$ heroku addons:create jawsdb:kitefin

I have so many problems with ClearDB. 我对ClearDB有很多问题。

If you must use ClearDB, I recommend adding a connectionTestQuery to your database connection pool configuration. 如果必须使用ClearDB,建议将connectionTestQuery添加到数据库连接池配置中。 I'm not sure how to do this generically, but if you are using HikariCP (which is great and you should use), you can add something like: 我不确定如何通用地执行此操作,但是如果您使用的是HikariCP (这很好,应该使用),则可以添加以下内容:

<property name="hibernate.hikari.connectionTestQuery">SELECT 1</property>

ClearDB routinely closes connections with idle/sleep status for more than 60 seconds. ClearDB通常会以空闲/睡眠状态关闭60秒钟以上的连接。 This happens when your system think it has a DB connection but the remote host has closed it. 当您的系统认为它具有数据库连接但远程主机已将其关闭时,就会发生这种情况。 As the previous respondent mentioned, a quick connectionTestQuery should resolve this. 如先前的受访者所述,快速的connectionTestQuery应该可以解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM