title: Hibernate connection lost after 10 to 12 hours of inactivity
body: <p>This has started to be a big problem for me. </p>
  
  <p>If the website is <strong>not used for like 10-12 hours plus</strong>. Then this error occurs and <strong>no hibernate connection is possible after that</strong>.. </p>
  
  <p>Only way to make <strong>site work again is by restarting the domain</strong>.</p>
  
  <pre><code>[2016-02-16T08:50:57.729+0530] [glassfish 4.1] [WARN] [] [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] [tid: _ThreadID=26 _ThreadName=http-listener-1(2)] [timeMillis: 1455592857729] [levelValue: 900] [[
    SQL Error: 0, SQLState: 08S01]]
  
  [2016-02-16T08:50:57.730+0530] [glassfish 4.1] [ERROR] [] [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] [tid: _ThreadID=26 _ThreadName=http-listener-1(2)] [timeMillis: 1455592857730] [levelValue: 1000] [[
    The last packet successfully received from the server was 36,572,564 milliseconds ago.  The last packet sent successfully to the server was 36,572,565 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.]]
  
  [2016-02-16T08:50:57.752+0530] [glassfish 4.1] [WARNING] [] [javax.enterprise.web] [tid: _ThreadID=26 _ThreadName=http-listener-1(2)] [timeMillis: 1455592857752] [levelValue: 900] [[
    StandardWrapperValve[Home]: Servlet.service() for servlet Home threw exception
  org.hibernate.exception.JDBCConnectionException: could not extract ResultSet
      at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:132)
      at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
      at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:89)
      at org.hibernate.loader.Loader.getResultSet(Loader.java:2065)
      at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1862)
      at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1838)
      at org.hibernate.loader.Loader.doQuery(Loader.java:909)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)
      at org.hibernate.loader.Loader.doList(Loader.java:2551)
      at org.hibernate.loader.Loader.doList(Loader.java:2537)
      at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2367)
      at org.hibernate.loader.Loader.list(Loader.java:2362)
      at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:126)
      at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1678)
      at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:380)
      at opController.Home.getLogin(Home.java:93)
      at opController.Home.doPost(Home.java:61)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
      at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
      at org.glassfish.tyrus.servlet.TyrusServletFilter.doFilter(TyrusServletFilter.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
      at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
      at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
      at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
      at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
      at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
      at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
      at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
      at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
      at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
      at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
      at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
      at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 36,572,564 milliseconds ago.  The last packet sent successfully to the server was 36,572,565 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
      at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
      at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1117)
      at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3871)
      at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2484)
      at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)
      at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2794)
      at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
      at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2322)
      at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:116)
      at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:80)
      ... 49 more
  Caused by: java.net.SocketException: Broken pipe
      at java.net.SocketOutputStream.socketWrite0(Native Method)
      at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
      at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
      at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
      at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
      at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3852)
      ... 56 more
  ]]
  </code></pre>
  
  <p>..</p>
  
  <pre><code>  [2016-02-16T08:51:50.287+0530] [glassfish 4.1] [WARNING] [] [com.mchange.v2.c3p0.impl.NewPooledConnection] [tid: _ThreadID=27 _ThreadName=http-listener-1(3)] [timeMillis: 1455592910287] [levelValue: 900] [[
        [c3p0] A PooledConnection that has already signalled a Connection error is still in use!]]
  
      [2016-02-16T08:51:50.290+0530] [glassfish 4.1] [WARNING] [] [com.mchange.v2.c3p0.impl.NewPooledConnection] [tid: _ThreadID=27 _ThreadName=http-listener-1(3)] [timeMillis: 1455592910290] [levelValue: 900] [[
        [c3p0] Another error has occurred [ com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 36,625,137 milliseconds ago.  The last packet sent successfully to the server was 36,625,138 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem. ] which will not be reported to listeners!
      com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 36,625,137 milliseconds ago.  The last packet sent successfully to the server was 36,625,138 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
          at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
          at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
          at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
          at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1117)
          at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3871)
          at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2484)
          at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)
          at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2794)
          at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
          at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2322)
          at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:116)
          at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:80)
          at org.hibernate.loader.Loader.getResultSet(Loader.java:2065)
          at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1862)
          at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1838)
          at org.hibernate.loader.Loader.doQuery(Loader.java:909)
          at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)
          at org.hibernate.loader.Loader.doList(Loader.java:2551)
          at org.hibernate.loader.Loader.doList(Loader.java:2537)
          at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2367)
          at org.hibernate.loader.Loader.list(Loader.java:2362)
          at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:126)
          at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1678)
          at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:380)
          at opController.Home.getLogin(Home.java:93)
          at opController.Home.doPost(Home.java:61)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
          at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
          at org.glassfish.tyrus.servlet.TyrusServletFilter.doFilter(TyrusServletFilter.java:305)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
          at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
          at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
          at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
          at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
          at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
          at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
          at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
          at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
          at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
          at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
          at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
          at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
          at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
          at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
          at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
          at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
          at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
          at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
          at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
          at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
          at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
          at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
          at java.lang.Thread.run(Thread.java:745)
      Caused by: java.net.SocketException: Broken pipe
          at java.net.SocketOutputStream.socketWrite0(Native Method)
          at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
          at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
          at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
          at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
          at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3852)
          ... 56 more
      ]]
  </code></pre>
  
  <p>I also posting my hibernate configuration file too.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
          &lt;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
          &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost:3306/db_name?autoReconnect=true&lt;/property&gt;
          &lt;property name="hibernate.connection.username"&gt;user&lt;/property&gt;
          &lt;property name="hibernate.connection.password"&gt;****&lt;/property&gt;
          &lt;property name="hibernate.hbm2ddl.auto"&gt;validate&lt;/property&gt;
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
          &lt;property name="format_sql"&gt;true&lt;/property&gt;
          &lt;property name="hibernate.current_session_context_class"&gt;org.hibernate.context.internal.ThreadLocalSessionContext&lt;/property&gt;
  
          &lt;!-- c3p0 Connection Pool Properties --&gt;
          &lt;property name="hibernate.connection.pool_size"&gt;1&lt;/property&gt;
          &lt;property name="hibernate.c3p0.min_size"&gt;1&lt;/property&gt;
          &lt;property name="hibernate.c3p0.max_size"&gt;100&lt;/property&gt; 
          &lt;property name="hibernate.c3p0.timeout"&gt;0&lt;/property&gt;
          &lt;property name="hibernate.c3p0.max_statements"&gt;0&lt;/property&gt;
          &lt;property name="hibernate.c3p0.idle_test_period"&gt;0&lt;/property&gt;
  
          &lt;mapping class="POJO.EXAMPLE"/&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>