-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Postgres connections remaining IDLE
PostPosted: Thu Aug 20, 2009 9:59 am 
Newbie

Joined: Thu Aug 20, 2009 4:22 am
Posts: 7
Spring 2.5.6
Hibernate3
c3po 0.9.1
postgres 8.2

my postgres connections remain idle, even when I set the
Code:
<property name="maxIdleTime" value="5"/>


in my spring-config.xml file.

Is there any reason why hibernate/spring/c3po will not remove idle connections in postgres?

The only way of removing them at the moment is using:
Code:
<property name="unreturnedConnectionTimeout" value="10"/>

It works but it's stupendously bad way of doing it I think.

spring-config.xml

Code:
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans.xsd
               http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context.xsd
               http://www.springframework.org/schema/tx
               http://www.springframework.org/schema/tx/spring-tx.xsd
               http://www.springframework.org/schema/aop
               http://www.springframework.org/schema/aop/spring-aop.xsd">
   
   <bean id="datasourceGD"
      class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
      <property name="driverClass" value="org.postgresql.Driver" />
      <property name="jdbcUrl" value="jdbc:postgresql://localhost/digital" />
      <property name="user" value="digital" />
      <property name="password" value="d1gital" />
      <property name="maxPoolSize" value="50"/>
      <property name="minPoolSize" value="1"/>

      <property name="maxIdleTime" value="5"/>
      <!--<property name="maxIdleTimeExcessConnections" value="3"/>-->
       <!-- <property name="testConnectionOnCheckin" value="true"/>-->
        <!--<property name="unreturnedConnectionTimeout" value="10"/>-->
         <!--<property name="debugUnreturnedConnectionStackTraces" value="true"/>-->
         <!--<property name="automaticTestTable" value="true"/>-->
       
   </bean>
   <bean id="transactionManager"
      class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      <property name="sessionFactory" ref="sessionFactory" />
   </bean>
   <bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <property name="dataSource" ref="datasourceGD" />
      <property name="configLocation" value="classpath:hibernate.cfg.xml" />
      <property name="hibernateProperties">
         <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect
            </prop>
            
            <prop key="hibernate.jdbc.batch_size">0</prop>
            <!-- second level cache -->
            <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider
            </prop>
            <prop key="hibernate.cache.use_query_cache">true</prop>
            <prop key="hibernate.cache.use_minimal_puts">true</prop>
               <prop key="hibernate.cache.use_second_level_cache">true</prop>


            <!-- <prop key="hibernate.max_fetch_depth">100</prop>  -->
            <!-- logging properties -->
            <prop key="hibernate.show_sql">false</prop>
            <prop key="hibernate.format_sql">false</prop>
            <prop key="hibernate.use_sql_comments">false</prop>
         </props>
      </property>
   </bean>

</beans>


Cheers

Euan


Top
 Profile  
 
 Post subject: Re: Postgres connections remaining IDLE
PostPosted: Tue Aug 25, 2009 4:35 am 
Newbie

Joined: Thu Aug 20, 2009 4:22 am
Posts: 7
I discovered, after a lot of searching, that the line

Code:
<tx:annotation-driven/>


was missing from my spring-config.xml file.

Not having thismeant that BEGINS were not being added to queries adn therefore queries were being left <IDLE> in transaction.

After making sure this new line was added, the transaction manager takes care of the connections.

Only took 4 days to figure it out...

Euan


Top
 Profile  
 
 Post subject: Re: Postgres connections remaining IDLE
PostPosted: Tue Aug 25, 2009 8:16 am 
Newbie

Joined: Sat May 26, 2007 8:18 am
Posts: 9
好贴啊 不错啊 谢谢楼主分享 拉 (*^__^*) 嘻嘻……








------------------------------------------------------------
刘嘉玲爱菲烟克在你展开藏起百消去斑


Top
 Profile  
 
 Post subject: Re: Postgres connections remaining IDLE
PostPosted: Tue Aug 25, 2009 8:25 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Quote:
I discovered, after a lot of searching.


Sometimes the most difficult of problems have the simplest solution. I'm sorry nobody on the board was able to come to your rescue earlier. Thanks for posting back with the solution. It'll help plenty of others in the future!

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.