Note that there are some explanatory texts on larger screens.

plurals
  1. POPostgresql + Hibernate3 + C3p0 = not closing connections
    primarykey
    data
    text
    <p>This only happens until peak load of the system.</p> <p>Hibernate exception:</p> <pre><code>org.hibernate.exception.JDBCConnectionException: could not execute query </code></pre> <p>org.postgresql.util.PSQLException: An I/O error occured while sending to the backend. java.io.IOException: Stream closed</p> <pre><code>postgresql log entry: 2011-08-10 05:27:35 UTC LOG: unexpected EOF on clien </code></pre> <p>t connection</p> <p>Here is my hibernate xml file</p> <pre><code>&lt;!-- Database connection settings --&gt; &lt;property name="connection.driver_class"&gt;org.postgresql.Driver&lt;/property&gt; &lt;property name="connection.url"&gt;jdbc:postgresql://[url]/sa_server&lt;/property&gt; &lt;property name="connection.username"&gt;[user]&lt;/property&gt; &lt;property name="connection.password"&gt;[pw]&lt;/property&gt; &lt;property name="hibernate.connection.provider_class"&gt;org.hibernate.connection.C3P0ConnectionProvider&lt;/property&gt; &lt;property name="hibernate.c3p0.min_size"&gt;3&lt;/property&gt; &lt;property name="hibernate.c3p0.max_size"&gt;5&lt;/property&gt; &lt;property name="hibernate.c3p0.timeout"&gt;1800&lt;/property&gt; &lt;property name="hibernate.c3p0.idle_test_period"&gt;100&lt;/property&gt; &lt;!-- SQL dialect --&gt; &lt;property name="hibernate.dialect"&gt;org.hibernatespatial.postgis.PostgisDialect&lt;/property&gt; &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt; &lt;!-- Disable the second-level cache --&gt; &lt;property name="cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt; &lt;!-- Echo all executed SQL to stdout --&gt; &lt;property name="show_sql"&gt;false&lt;/property&gt; </code></pre> <p>EDIT----</p> <p>Here is the code I am calling to get and close the session.</p> <pre><code>// perform the operation itself try { session = AppSessionFactory.openSession(); session.beginTransaction(); session.setFlushMode( FlushMode.COMMIT ); if ( pre() ) { if ( doWork() ) { if ( post() ) { session.getTransaction().commit(); } } } if ( !response.success ) { session.getTransaction().rollback(); } } catch ( Exception e ) { if ( session != null ) { try { session.getTransaction().rollback(); } catch ( Exception e2 ) {} } // attempt to retrieve a useful error for the invoker outerException = e; Throwable cause = outerException.getCause(); if ( cause != null &amp;&amp; cause instanceof SQLException ) { Exception rootCause = ((SQLException)cause).getNextException(); if ( rootCause != null ) { innerException = rootCause; } } } finally { if ( session != null ) { session.close(); } } </code></pre> <p>EDIT--</p> <pre><code>public class AppSessionFactory { private static AppSessionFactory instance = null; private final SessionFactory sessionFactory = new Configuration() .configure() // configures settings from hibernate.cfg.xml .buildSessionFactory(); private AppSessionFactory() {} @Override protected void finalize() { if ( sessionFactory != null ) { sessionFactory.close(); } } private static AppSessionFactory instance() { if ( instance == null ) { instance = new AppSessionFactory(); } return instance; } public static Session openSession() { return instance().sessionFactory.openSession(); } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload