-->
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.  [ 2 posts ] 
Author Message
 Post subject: Debugging Connection Leaks with C3P0
PostPosted: Wed Mar 15, 2006 7:15 pm 
Newbie

Joined: Mon Jan 23, 2006 5:55 pm
Posts: 2
This is a pretty general question and I apologize in advance if it's been covered here before. I'm having problems using hibernate and c3p0 wherein my c3p0 connection pool becomes exhausted. I'm trying to debug this problem by putting stacktrace logging calls into the c3p0 source on checkin/checkout of connections. I'm sure there's a better way to do this, can anyone suggest anything?


Top
 Profile  
 
 Post subject: ConnectionPool
PostPosted: Tue Mar 21, 2006 12:38 pm 
Newbie

Joined: Fri Aug 19, 2005 4:39 am
Posts: 5
I've encountered a similar problem using Proxool.

I've also debugged and located the problem:

The connections are exhausted in the following case:

You load entities within a transaction, and commit the transaction. If you try to access a uninitialized association, hibernate initializes lazy associations: a connection is requested and not freed anymore.

Therefore my solution was to free them manually:

in the getter of one-to-one associations put the following:

if (!((HibernateProxy) ref).getHibernateLazyInitializer().getSession()
.getJDBCContext().isTransactionInProgress()) {
((HibernateProxy) ref).getHibernateLazyInitializer().getSession()
.getJDBCContext().afterNontransactionalQuery(true);
}


(while ref is the proxy).

on one-to-many:

if (!persistentSet.getCurrentSession().getJDBCContext().isTransactionInProgress()) {
persistentSet.getCurrentSession().getJDBCContext().afterNontransactionalQuery(true);
}

(while persistenSet is the Hibernate Proxy (PersistentSet)), if you use another collection type, use it instead.


The core is if you are not in a transaction, hibernate forgets to free the connection used for lazy loading, afterNonTransactionalQuery does this.


Hope this helps!


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