title: PostgreSQL connection limit exceeded for non-superusers
body: <p>I am using a spring application and I am getting following exception as:</p>
  
  <pre><code>Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Cannot open connection.
  </code></pre>
  
  <p>When I am manually trying to connect to the database using DBVisualizer I am getting following error</p>
  
  <pre><code>An error occurred while establishing the connection:
  
  Long Message:
  FATAL: connection limit exceeded for non-superusers
  
  Details:
     Type: org.postgresql.util.PSQLException
     Error Code: 0
     SQL State: 53300
  </code></pre>
  
  <p>Here is my spring-context.xml file</p>
  
  <pre><code>&lt;jee:jndi-lookup id="dataSource1" jndi-name="jdbc/PmdDS"/&gt;
  
  
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource1" /&gt;
          &lt;property name="configLocation"&gt;
              &lt;value&gt;classpath:hibernate.cfg.xml&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="configurationClass"&gt;
              &lt;value&gt;org.hibernate.cfg.AnnotationConfiguration&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
                  &lt;prop key="current_session_context_class"&gt;thread&lt;/prop&gt;
                  &lt;prop key="cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/prop&gt;
  
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>My question is I am getting this error because that I have not added following line in spring-context.xml</p>
  
  <pre><code> &lt;prop key="hibernate.connection.release_mode"&gt;auto&lt;/prop&gt;
  </code></pre>
  
  <p>Will adding this line will solve my problem. I am fearing that my application is creating connection but not releasing the database connection because I have not added the above line in spring-context.xml..
  Note I am not using HibernateTemplate . I am using <code>sessionFactory.getCurrentSession().createQuery("").list()</code> to fire my queries
  My Context.xml details</p>
  
  <pre><code>&lt;Context&gt;
       Specify a JDBC datasource 
      &lt;Resource name="jdbc/PmdDS" 
                auth="Container"
                type="javax.sql.DataSource" 
                username="sdfsfsf" 
                password="sfsdfsdf" maxActive="-1"
                driverClassName="org.postgresql.Driver"
                url="jdbc:postgresql://111.11.11.11:5432/test"/&gt;
  
  
  &lt;/Context&gt;
  </code></pre>
  
  <p>Please suggest any solution</p>