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.
分享到:
相关推荐
在编程过程中,尤其是在使用C#进行文件系统操作时,可能会遇到这样一个问题:当你尝试删除一个目录,系统返回“System.IO.IOException: 目录不是空的”错误。这意味着该目录下仍有文件或子目录存在,因此无法直接...
在Java编程中,"java.io.FileNotFoundException: ***** (Too many open files)" 是一个常见的错误,意味着程序尝试打开的文件数量超过了操作系统的限制。这个错误通常出现在处理大量文件或长时间运行的程序中,尤其...
java安装路径Java\jre\lib\security下替换这两个架包,即可解决 java.security.cert.CertificateException: Unable to initialize, java.io.IOException: Short read of DER length
在Java编程环境中,"java.security.InvalidKeyException: illegal Key Size" 是一个常见的错误,通常发生在加密或解密操作中。这个错误表示你试图使用的密钥长度超过了Java默认的安全限制。在给定的上下文中,这个...
1. **安装 Java**:Jenkins 需要 Java 运行环境,确保系统已安装最新版的 JDK。 2. **下载 Jenkins**:从官方网站获取适合 Linux 平台的 Jenkins 可执行文件。 3. **启动 Jenkins**:通过命令行启动 Jenkins,例如...
Java.io.IOException: The same input jar [E:\Android\myProgram\angel\libs\alipaySdk-20160825.jar] is specified twice. 首先 看一下我项目中关于此jar的配置,我在libs中导入了alipaySdk-20160825.jar,
在Eclipse集成开发环境(IDE)中使用ANT进行项目构建时,可能会遇到特定的错误提示:“Javadoc failed java.io.IOException Cannot run program javadoc”。这个错误信息表明在生成Java文档的过程中出现了问题,具体...
报错:java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.-附件资源
把 java 代码直接改成 jsp,上传时产生 如下异常: 2012-12-31 8:59:21 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet jsp threw exception java.io.IOException: ...
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...
在Java编程环境中,进行串口通信时,常常会遇到一个问题:缺少`gnu.io`包,导致无法正常编译或运行程序。这个问题主要出现在使用RXTX库进行串口操作的项目中。RXTX是一个开源的Java库,它提供了与硬件进行串行通信的...
Exception in thread “main” java. lang . UnsatisfiedLinkError: org. apache . hadoop. io. nativeio. NativeIOSWindows . access0 (Ijava/ lang/String;I)Z 原因:在调用NativeIO中的...
Java中的`CharConversionException`是`IOException`的一个子类,主要在字符编码转换过程中遇到问题时抛出。在你的问题中,错误提示是"java.io.CharConversionException: isHexDigit",这通常意味着在处理字符或字符...
主要介绍了 AndroidApk混淆编译时,报告Error:Execution failed for task ‘:gviews:transformClassesAndResourcesWithProguardForRelease’.错误解决办法的相关资料,需要的朋友可以参考下
问题1:TOMCAT下载文件出错:org.apache.catalina.connector.ClientAbortException. 问题2:TOMCAT记录接收数据大小、发送数据大小和请求处理时间
import java.io.IOException; import java.nio.file.*; public class FileMoveExample { public static void main(String[] args) { Path source = Paths.get("path_to_source_file"); Path target = Paths.get...
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
import java.io.*; import java.util.zip.*; public class GzipCompressor { public static void compressFile(String inputFile, String outputFile) throws IOException { FileOutputStream fos = new ...