title: Connection reset in long session
body: <p>I have a standalone Thread application. Which is a listener waiting for a message, and when it arrives do somethings, in which I have to save in the DB the message. 
  But I have problems because if I run the application and "send manually a message" everythings works fine, but if I run the application and wait for a message of the system (for instance one hour after it arrives) when the APP 's going to save to the DB it sinks, telling:</p>
  
  <p>java.sql.SQLException: Io exception: Connection reset
  or
  java.sql.BatchUpdateException: Io Exception: Connection reset</p>
  
  <p>I'm using Hibernate 3.2.6 with C3p0 0.9.2.1</p>
  
  <p>The configuration of the session is:</p>
  
  <pre><code>public final class PersistenceUtil{
      private static final SessionFactory sessionFactory;
  
      static {
          try {
              String location = ServiceLocator.getInstance().getConfigurationService().getProperty("adaptor.location");
              if (LOC_1.equals(location)) {
                  sessionFactory = new AnnotationConfiguration().configure("hibernate.1.cfg.xml").buildSessionFactory();
              } else if(LOC_2.equals(location)) {
                  sessionFactory = new AnnotationConfiguration().configure("hibernate.2.cfg.xml").buildSessionFactory();
              }else {
                  sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
              }
              sessionFactory.openSession();
          } catch (Throwable ex) {
              throw new ExceptionInInitializerError(ex);
          }
      }
  
  
      private PersistenceUtil() {
      }
  
      public static void shutdown() {
          try {
              sessionFactory.close();
          } catch (HibernateException e) {
              LOG.error("PersistanceUtil.shutdown Error: " + e.getMessage());
          }
  
      }
  
      public static SessionFactory getSessionFactory() {
          return sessionFactory;
      }
  </code></pre>
  
  <p>When I want to save I do (and where is the error):</p>
  
  <pre><code>public T save(T entity) {
  
          if (!getSession().getTransaction().isActive()) {
              log.warn("Session not active. Starting the session");
              getSession().beginTransaction();
          }
  
          getSession().save(entity);
          getSession().getTransaction().commit();
          return entity;
      }
  </code></pre>
  
  <p>And my hibernate.cfg.xml is:</p>
  
  <pre><code>&lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;!-- Database connection settings --&gt;
          &lt;property name="connection.driver_class"&gt;oracle.jdbc.driver.OracleDriver&lt;/property&gt;
          &lt;property name="connection.url"&gt;URL&lt;/property&gt;
          &lt;property name="connection.username"&gt;USER&lt;/property&gt;
          &lt;property name="connection.password"&gt;Password&lt;/property&gt;
  
          &lt;!-- SQL dialect --&gt;
          &lt;property name="dialect"&gt;org.hibernate.dialect.Oracle10gDialect&lt;/property&gt;
          &lt;!-- &lt;property name="hibernate.hbm2ddl.auto"&gt;update&lt;/property&gt; --&gt;
          &lt;!-- Enable Hibernate's automatic session context management --&gt;
          &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
          &lt;property name="hibernate.transaction.factory_class"&gt;org.hibernate.transaction.JDBCTransactionFactory&lt;/property&gt;
          &lt;!-- Echo all executed SQL to stdout --&gt;
          &lt;property name="show_sql"&gt;true&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;3000&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="MessageEO" /&gt;
          &lt;mapping class="CustomerEO" /&gt;
  
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>What am I doing wrong?
  Thanks in advance</p>