非超级用户超出了PostgreSQL连接限制

Raj*_*esh 6 postgresql hibernate

我正在使用spring应用程序,我得到以下异常:

Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Cannot open connection.
Run Code Online (Sandbox Code Playgroud)

当我手动尝试使用DBVisualizer连接到数据库时,我收到以下错误

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
Run Code Online (Sandbox Code Playgroud)

这是我的spring-context.xml文件

<jee:jndi-lookup id="dataSource1" jndi-name="jdbc/PmdDS"/>


    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource1" />
        <property name="configLocation">
            <value>classpath:hibernate.cfg.xml</value>
        </property>
        <property name="configurationClass">
            <value>org.hibernate.cfg.AnnotationConfiguration</value>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="current_session_context_class">thread</prop>
                <prop key="cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>

            </props>
        </property>
    </bean>
Run Code Online (Sandbox Code Playgroud)

我的问题是我收到此错误,因为我没有在spring-context.xml中添加以下行

 <prop key="hibernate.connection.release_mode">auto</prop>
Run Code Online (Sandbox Code Playgroud)

将添加此行将解决我的问题.我担心我的应用程序正在创建连接但没有释放数据库连接,因为我没有在spring-context.xml中添加上面的行.注意我没有使用HibernateTemplate.我sessionFactory.getCurrentSession().createQuery("").list()用来触发我的查询我的Context.xml详细信息

<Context>
     Specify a JDBC datasource 
    <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"/>


</Context>
Run Code Online (Sandbox Code Playgroud)

请建议任何解决方案

Fra*_*man 2

问题出在数据源的配置上

最大连接数的默认值高于 postgres 中设置的最大连接数,并且当 hibernate 请求另一个连接时,数据源会尝试创建一个连接。

你能展示一下你的数据源的配置吗?