-->
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.  [ 10 posts ] 
Author Message
 Post subject: [Commons DBCP] Cannot get a connection, pool exhausted
PostPosted: Tue Apr 18, 2006 11:10 am 
Newbie

Joined: Tue Apr 18, 2006 11:05 am
Posts: 5
Hi All,
I am using DBCP with Hibernate, when I deploy my server application it
works fine for some hours and after that for any successive request it
throws

<stacktrace>
org.hibernate.exception.GenericJDBCException: Cannot open connection
at
org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLSta
teConverter.java:82)
at
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java
:43)
at
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java
:29)
at
org.hibernate.jdbc.AbstractBatcher.openConnection(AbstractBatcher.java:427)
at org.hibernate.jdbc.JDBCContext.connect(JDBCContext.java:168)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:103)
at
org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:49)
at
org.hibernate.transaction.JDBCTransactionFactory.beginTransaction(JDBCTransa
ctionFactory.java:24)
at
org.hibernate.jdbc.JDBCContext.beginTransaction(JDBCContext.java:231)
at
org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1073)
...........
at java.util.TimerThread.mainLoop(Timer.java:432)
at java.util.TimerThread.run(Timer.java:382)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot get a
connection, pool exhausted
at
org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.ja
va:103)
at
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:5
40)
at
com.xxx.DBCPConnectionProvider.getConnection(DBCPConnectionProvider.java:243
)
at
org.hibernate.jdbc.AbstractBatcher.openConnection(AbstractBatcher.java:424)
... 11 more
Caused by: java.util.NoSuchElementException: Timeout waiting for idle object
at
org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPoo
l.java:756)
at
org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.ja
va:95)
... 14 more
</stacktrace>

Can anyone please tell me whets going wrong ?
here is my configuration
j2sdk 1.4.2_6
hibernate 3.0
commons-pool 1.2
commons-dbcp 1.2.1
fedora core 3
and
hibernate config file looks like

<property
name="hibernate.connection.provider_class">com.xxx.DBCPConnectionProvider</p
roperty>
<property name="hibernate.connection.pool_size">20</property>
<property name="hibernate.dbcp.initialSize">10</property>
<property name="hibernate.dbcp.maxWait">10000</property>
<property name="hibernate.dbcp.validationQuery">select 1</property>

I have taken com.xxx.DBCPConnectionProvider from
http://wiki.apache.org/jakarta-commons/DBCP/Hibernate


Thanks&Regards
~Preetam



Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 11:26 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Are you closing your Hibernate Sessions?

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 19, 2006 7:30 am 
Newbie

Joined: Tue Apr 18, 2006 11:05 am
Posts: 5
even if i dont close hibernate session, hibernate will close those for me right ?
the finalize() of org.hibernate.jdbc.JDBCContext will do this job for me right ?
i checked the hibernate log and i have seen ....
2006 04 19 11:20:53 ADC [Finalizer] [DEBUG] JDBCContext.finalize() - running Session.finalize()
2006 04 19 11:20:53 ADC [Finalizer] [WARN ] JDBCContext.finalize() - unclosed connection, forgot to call close() on your session?

it means when the session object will get garbage colleced at that time it will close the corresponding connection ....

any other thoughts ?


Top
 Profile  
 
 Post subject: Connection Pool Exhausted
PostPosted: Fri Apr 21, 2006 7:33 am 
Newbie

Joined: Tue Oct 05, 2004 9:21 am
Posts: 7
Location: Dublin, Ireland
Hi Preetam,

Just wondering whether you have got anywhere with your issue? I am getting the same problem - it seems as though the connections are not being released back into the pool when finished with. I have looked at this in debug, and sessions are being closed.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 21, 2006 11:29 am 
Beginner
Beginner

Joined: Fri Oct 28, 2005 10:46 am
Posts: 37
Preetam wrote:
even if i dont close hibernate session, hibernate will close those for me right ?
the finalize() of org.hibernate.jdbc.JDBCContext will do this job for me right ?
i checked the hibernate log and i have seen ....
2006 04 19 11:20:53 ADC [Finalizer] [DEBUG] JDBCContext.finalize() - running Session.finalize()
2006 04 19 11:20:53 ADC [Finalizer] [WARN ] JDBCContext.finalize() - unclosed connection, forgot to call close() on your session?

it means when the session object will get garbage colleced at that time it will close the corresponding connection ....

any other thoughts ?


That's very likely your problem. Do you see the message that says, "unclosed connection, forgot to call close() on your session?". That's there at the WARN level for a reason: so that you'll see it and do something about it. You have no way of knowing when (or even if) finalize will be called or how many of those objects will pile up before one or more of them are garbage collected. A very good rule of thumb is "Never ever ever *ever* rely on garbage collection/finalize to release database connections (or other similar high-demand resources)."


Top
 Profile  
 
 Post subject: Connection Pool Exhausted
PostPosted: Fri Apr 21, 2006 11:33 am 
Newbie

Joined: Tue Oct 05, 2004 9:21 am
Posts: 7
Location: Dublin, Ireland
I noticed the problem occurred on one particular form that we were using. I modified the corresponding mapping files to have lazy initialisation set to false i.e. lazy="false" - this seemed to resolve our problem - hopefully it will help yours!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 21, 2006 12:12 pm 
Newbie

Joined: Tue Mar 09, 2004 11:17 pm
Posts: 8
I don't thibk lazy initialization has anything to do. If it seemed to go away, it was by pure chance.

I had a problem like that a few days ago, my connection pool was getting exhausted after a few hours running. It was indeed an unclosed session.

Your log is telling you you have opened connections, do as they told you and look for your missing session.close().


Top
 Profile  
 
 Post subject: [Commons DBCP] Cannot get a connection, pool exhausted
PostPosted: Mon Apr 24, 2006 3:18 am 
Newbie

Joined: Tue Oct 05, 2004 9:21 am
Posts: 7
Location: Dublin, Ireland
We were using the second level cache on lookup items from this mapping file. When the application was used to modify contents of this form, it appears that a db connection was held on to as hibernate needs an open connection for lazy classes.

After extensive debugging of the problem, we discovered that once lazy initialization was set to false, the connections were indeed released correctly. So unfortunately for me - it wasn't pure chance that sorted the problem!

We had not left any connection closed, and the code that gives the warning itself closes the connection.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 24, 2006 7:49 am 
Beginner
Beginner

Joined: Fri Oct 28, 2005 10:46 am
Posts: 37
Hibernate doesn't "hold on" to any connections unless you tell it to, especially where lazy loading is concerned. One of the big problems new Hibernate users encounter is the LazyInitializationException because of a closed Session/connection.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 05, 2006 7:45 am 
Newbie

Joined: Tue Apr 18, 2006 11:05 am
Posts: 5
zzantozz wrote:
A very good rule of thumb is "Never ever ever *ever* rely on garbage collection/finalize to release database connections (or other similar high-demand resources)."


yup ... i agree!

well we went through a code review phase and figured out many places in our code where we have forgotten to close the session. Now we closed the session and now the code code is working fine!


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