-->
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.  [ 6 posts ] 
Author Message
 Post subject: Please Help! problem with C3P0
PostPosted: Mon Jan 21, 2008 6:44 am 
Beginner
Beginner

Joined: Sat Oct 08, 2005 2:13 am
Posts: 47
Hi all,

I have a problem with connection pooling using C3P0, the problem is, after opening a hibernate session and some transaction the following exception will be thrown, it seems something wrong with c3p0.

if anyone had such experience please enlighten me on this issue.


Hibernate version: 3.2

Mapping documents: HBM files

Code in which I acquire the current session:
Code:
public static Session currentSession () {

        Session s = (Session)session.get();

        if (s == null) {

            try {

                s= sessionFactory.openSession();

                s.connection().setAutoCommit(true);

                session.set(s);

            } catch (SQLException e) {

                s.close() ;

                return null ;

}

        }



        return s ;

    }


Full stack trace of any exception that occurs:
Code:
WARN BasicResourcePool com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask:1841 run - com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@ae525c -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:

java.sql.SQLException: Data source rejected establishment of connection,  message from server: "Too many connections"

            at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:990)

            at com.mysql.jdbc.Connection.createNewIO(Connection.java:2544)

            at com.mysql.jdbc.Connection.<init>(Connection.java:1474)

            at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:264)

            at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)

            at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)

            at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)

            at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)

            at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)

            at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)

            at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)

            at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

!

!



Name and version of the database you are using:Mysql 4


Hibernate & c3p0 settings: (in hibernate.cfg.xml)
Code:
<hibernate-configuration>

            <session-factory>

                        <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>

                        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>

                        <property name="connection.url">jdbc:mysql://localhost/otpwithebTracker?characterEncoding=utf8</property>

                        <property name="connection.username">root</property>

                        <property name="connection.password"></property>

                        <property name="show_sql">true</property>

        <property name="hibernate.c3p0.min_size">5</property>

        <property name="hibernate.c3p0.max_size">20</property>

        <property name="hibernate.c3p0.acquire_increment">1</property>

        <property name="hibernate.c3p0.timeout">60</property>





Any help would be appreciated.


Top
 Profile  
 
 Post subject: Re: Please Help! problem with C3P0
PostPosted: Mon Jan 21, 2008 11:22 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Open your MySQL admin console and see how many connections you have. It seems more like MySQL is rejecting the request for a new connection.



Farzad-


Top
 Profile  
 
 Post subject: Re: Please Help! problem with C3P0
PostPosted: Mon Jan 21, 2008 1:04 pm 
Beginner
Beginner

Joined: Sat Oct 08, 2005 2:13 am
Posts: 47
farzad wrote:
Open your MySQL admin console and see how many connections you have. It seems more like MySQL is rejecting the request for a new connection.



Farzad-


thanks, yes in fact, the number of connection exceeds the value specified in Hibernate config file and the problem is that, because Hibernate or rather c3p0 should release connections that no longer is used but it doesn't function properly

as you can see I set the maximum size to 20 but even is a small scale test case in which we have only one user session, this value is exceeding!!!

_________________
Regards,
photos: http://pixelshot.wordpress.com
weblog: http://brainable.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 23, 2008 2:31 am 
Beginner
Beginner

Joined: Sat Oct 08, 2005 2:13 am
Posts: 47
any idea? :(

_________________
Regards,
photos: http://pixelshot.wordpress.com
weblog: http://brainable.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 26, 2008 1:38 am 
Beginner
Beginner

Joined: Sat Oct 08, 2005 2:13 am
Posts: 47
my project stopped progressing by this problem, please give me your advice.

thanks

_________________
Regards,
photos: http://pixelshot.wordpress.com
weblog: http://brainable.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 28, 2008 12:27 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
mnrz wrote:
my project stopped progressing by this problem, please give me your advice.

thanks


I don't know why I didn't get any notification for your reply but here I am now :)


Well, I don't have a good feeling about the acquire_increment parameter as also it appears to be depreciated in c3p0 API too. However, you could have problems returning connections to connection pool. Also you might want to try to switch to another connection that is more sensitive and gives more messages. JBoss connection pool is a good one and tells you when your application is not returning the connections. DBCP might be also good.



Farzad-


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.