hibernate 4 session connection remains open

216 Views Asked by At

I use hibernate with mysql database in a java application I migrate from hibernate 3 to hibernate 4 but in new hibernate number of busy thread increased and it use all of connections so my application stop working and can not give connection any more. my hibernate.cfg configuration is as bellow:

        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <!-- Disable the second-level cache -->
        <property name="hibernate.cache.use_second_level_cache">true</property>
        <!--<property name="hibernate.cache.provider_class">
            net.sf.ehcache.hibernate.EhCacheProvider
        </property>-->
        <property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</property>
        <property name="hibernate.cache.use_query_cache">true</property>

        <!--<property name="hibernate.generate_statistics">true</property>-->

        <!--C3P0 configure-->
        <property name="hibernate.connection.provider_class">
            org.hibernate.connection.C3P0ConnectionProvider
        </property>
        <property name="hibernate.c3p0.acquire_increment">3</property>
        <property name="hibernate.c3p0.idle_test_period">144</property>
        <property name="hibernate.c3p0.timeout">60</property>
        <property name="hibernate.c3p0.max_size">30</property>
        <property name="hibernate.c3p0.min_size">3</property>
        <property name="hibernate.c3p0.max_statements">0</property>
        <property name="hibernate.c3p0.preferredTestQuery">select 1;</property>
        <property name="hibernate.c3p0.validate">true</property>
        <property name="hibernate.c3p0.testConnectionOnCheckout">true</property>

I set timeout a small value and increase max_size and also set use_second_level_cache=false but no improvement is made

what is the problem

thanks a lot

1

There are 1 best solutions below

0
On

So this sounds very much like a Connection leak in your application. Use c3p0 config params unreturnedConnectionTimeout and debugUnreturnedConnectionStackTraces to debug it.

See here.

(In your hibernate.cfg they'd be hibernate.c3p0.unreturnedConnectionTimeout and hibernate.c3p0.debugUnreturnedConnectionStackTraces.)