{"id":591,"date":"2004-04-14T15:29:13","date_gmt":"2004-04-14T19:29:13","guid":{"rendered":"http:\/\/wordpress.cephas.net\/?p=591"},"modified":"2004-04-14T15:29:13","modified_gmt":"2004-04-14T19:29:13","slug":"hibernate-communication-link-failure-javaioioexception","status":"publish","type":"post","link":"https:\/\/cephas.net\/blog\/2004\/04\/14\/hibernate-communication-link-failure-javaioioexception\/","title":{"rendered":"Hibernate: Communication link failure: java.io.IOException"},"content":{"rendered":"<p>I recently launched a new site based on <a href=\"http:\/\/jakarta.apache.org\/struts\/\">Struts<\/a>, <a href=\"http:\/\/www.hibernate.org\/\">Hibernate<\/a> and <a href=\"http:\/\/www.mysql.com\/\">MySQL<\/a> and immediately ran into a weird issue where Hibernate lost the ability to make database connections after a long period of inactivity.  For the record, the stack trace is below:<br \/>\n<code><br \/>\njava.sql.SQLException: Communication link failure: java.io.IOException<br \/>\n&nbsp;&nbsp;at org.gjt.mm.mysql.MysqlIO.sendCommand(Unknown Source)<br \/>\n&nbsp;&nbsp;at org.gjt.mm.mysql.MysqlIO.sqlQueryDirect(Unknown Source)<br \/>\n&nbsp;&nbsp;at org.gjt.mm.mysql.Connection.execSQL(Unknown Source)<br \/>\n&nbsp;&nbsp;at org.gjt.mm.mysql.PreparedStatement.executeQuery(Unknown Source)<br \/>\n&nbsp;&nbsp;at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:83)<br \/>\n&nbsp;&nbsp;at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:794)<br \/>\n&nbsp;&nbsp;at net.sf.hibernate.hql.QueryTranslator.iterate(QueryTranslator.java:846)<br \/>\n&nbsp;&nbsp;at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1540)<br \/>\n&nbsp;&nbsp;at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1513)<br \/>\n&nbsp;&nbsp;at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1505)<br \/>\n<\/code><br \/>\nLooks like there are other people having the <a href=\"http:\/\/forum.hibernate.org\/viewtopic.php?t=929666&amp;highlight=communication+link+failure\">same<\/a> <a href=\"http:\/\/swforum.sun.com\/jive\/thread.jspa?threadID=23498&amp;tstart=75\">problem<\/a>,   the first suggestion was to use the <a href=\"http:\/\/www.hibernate.org\/42.html\">Thread Local Session pattern<\/a>, which I already had in place. The solution was to add the following properties to my hibernate.cfg.xml:<br \/>\n<code><br \/>\n&lt;property name=\"connection.autoReconnect\"&gt;true&lt;\/property&gt;<br \/>\n&lt;property name=\"connection.autoReconnectForPools\"&gt;true&lt;\/property&gt;<br \/>\n&lt;property name=\"connection.is-connection-validation-required\"&gt;true&lt;\/property&gt;<br \/>\n<\/code><br \/>\nwhich I believe are specific to MySQL, but as far as I can tell, aren&#8217;t documented anywhere on the Hibernate site (or should they be documented on the <a href=\"http:\/\/dev.mysql.com\/downloads\/connector\/j\/3.0.html\">MySQL JDBC driver site<\/a>?)<\/p>\n<p>For what it&#8217;s worth, Hibernate is a dream come true.  I don&#8217;t like writing create, update, and delete SQL statements and I&#8217;ve found that the software I&#8217;ve written is much easier to manage and troubleshoot.  If you haven&#8217;t played with it yet, check it out <a href=\"http:\/\/www.hibernate.org\/\">now<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently launched a new site based on Struts, Hibernate and MySQL and immediately ran into a weird issue where Hibernate lost the ability to make database connections after a long period of inactivity. For the record, the stack trace is below: java.sql.SQLException: Communication link failure: java.io.IOException &nbsp;&nbsp;at org.gjt.mm.mysql.MysqlIO.sendCommand(Unknown Source) &nbsp;&nbsp;at org.gjt.mm.mysql.MysqlIO.sqlQueryDirect(Unknown Source) &nbsp;&nbsp;at org.gjt.mm.mysql.Connection.execSQL(Unknown &hellip; <a href=\"https:\/\/cephas.net\/blog\/2004\/04\/14\/hibernate-communication-link-failure-javaioioexception\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Hibernate: Communication link failure: java.io.IOException<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/591"}],"collection":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/comments?post=591"}],"version-history":[{"count":0,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/591\/revisions"}],"wp:attachment":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/media?parent=591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/categories?post=591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/tags?post=591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}