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
at org.gjt.mm.mysql.MysqlIO.sendCommand(Unknown Source)
at org.gjt.mm.mysql.MysqlIO.sqlQueryDirect(Unknown Source)
at org.gjt.mm.mysql.Connection.execSQL(Unknown Source)
at org.gjt.mm.mysql.PreparedStatement.executeQuery(Unknown Source)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:83)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:794)
at net.sf.hibernate.hql.QueryTranslator.iterate(QueryTranslator.java:846)
at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1540)
at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1513)
at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1505)
Looks like there are other people having the same problem, the first suggestion was to use the Thread Local Session pattern, which I already had in place. The solution was to add the following properties to my hibernate.cfg.xml:
<property name="connection.autoReconnect">true</property>
<property name="connection.autoReconnectForPools">true</property>
<property name="connection.is-connection-validation-required">true</property>
which I believe are specific to MySQL, but as far as I can tell, aren't documented anywhere on the Hibernate site (or should they be documented on the MySQL JDBC driver site?)
For what it's worth, Hibernate is a dream come true. I don't like writing create, update, and delete SQL statements and I've found that the software I've written is much easier to manage and troubleshoot. If you haven't played with it yet, check it out now.
分享到:
相关推荐
解决删除目录提示:System.IO.IOException: 目录不是空的
java.security.InvalidKeyException:illegal Key Size 微信开发过程中,JDK6的版本
本人的一片博客,http://blog.csdn.net/jackieriver/article/details/78882194,所需要的一些插件
Eclipse 进行 ANT 时错误 Javadoc failed java.io.IOException Cannot run program javadoc
Java.io.IOException: The same input jar [E:\Android\myProgram\angel\libs\alipaySdk-20160825.jar] is specified twice. 首先 看一下我项目中关于此jar的配置,我在libs中导入了alipaySdk-20160825.jar,
复制并覆盖%JAVA_HOME%/jre/lib/security下的local_policy.jar 和 US_export_policy.jar
把 java 代码直接改成 jsp,上传时产生 如下异常: 2012-12-31 8:59:21 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet jsp threw exception java.io.IOException: ...
Exception in thread “main” java. lang . UnsatisfiedLinkError: org. apache . hadoop. io. nativeio. NativeIOSWindows . access0 (Ijava/ lang/String;I)Z 原因:在调用NativeIO中的...
java.io.IOException: Server returned HTTP response code: 403 for URL 处理过程记录 BASIC AUTH2 POST接口,解决403问题
针对java.io.IOException: entity content is too long [180278508] for the configured buffer limit [157286400]异常,将 DEFAULT_BUFFER_LIMIT修改为150M
it.sauronsoftware.jave.EncoderException: java.io.IOException: Cannot run program "C:\Users\moxiao\AppData\Local\Temp\jave-1\ffmpeg.exe": CreateProcess error=740, 请求的操作需要提升。 在最新的liunx ...
报错:java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.-附件资源
import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.StringReader; import java.util.ArrayList; import java.util.Collection; import java.util....
java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries. at org.apache.hadoop.util.Shell.getQualifiedBinPath(Shell.java:378) at org.apache.hadoop.util.Shell....
java.lang.ArrayIndexOutOfBoundsException: 128 at android.content.res.StringBlock.getShort(StringBlock.java:231) at android.content.res.StringBlock.getString(StringBlock.java:91) at android.content....
2. import java.io.IOException; 3. import java.io.PrintWriter; 4. import java.sql.Connection; 5. import java.sql.ResultSet; 6. import java.sql.Statement; 7. import java.sql.DriverManager;
JSSE(Java Security Socket Extension) 是Sun为了解决在Internet上的实现安全信息传输的解决方案。它实现了SSL和TSL(传输层安全)协议。在JSSE中包含了数据加密,服务器验证,消息完整性和客户端验证等技术。通过...
ERROR org.apache.hadoop.mapred.TaskTracker: Can not start task tracker because java.io.IOException: Failed to set permissions of path: \tmp\hadoop-admin \mapred\local\ttprivate to 0700 at org.apache...
1.写一段程序利用Scanner类扫描用户输入,假设用户输入: lvjia 37 D:\photo.jpg 将前两部分lvjia和37直接写入文件D:\test.bin;第三个部分是一个文件路径,检查文件(D:\photo.jpg)是否存在,如果存在将文件内容...