-->
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: the application cannot get a connection, pool exhausted
PostPosted: Wed Mar 28, 2007 4:47 am 
Newbie

Joined: Wed Mar 28, 2007 3:51 am
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.1

Mapping documents:
<beans>
<!-- Local DataSource that works in any environment -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"><value>oracle.jdbc.driver.OracleDriver</value></property>
<property name="url"><value>jdbc:oracle:thin:@192.168.0.49:1521:test</value></property>
<property name="username"><value>test</value></property>
<property name="password"><value>test</value></property>

<property name="maxActive"><value>100</value></property>
<property name="maxWait"><value>10000</value></property>
<property name="maxIdle"><value>30</value></property>
<property name="minIdle"><value>10</value></property>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource"><ref bean="dataSource"/></property>

<property name="mappingResources">
<list>
<value>Company.hbm.xml</value>
<value>CUser.hbm.xml</value>
... ...

Code between sessionFactory.openSession() and session.close():
bellow is one class:

public class FormDAOHibernate extends BaseDAOHibernate implements IFormDAO{
public void moveFormAnswerCount(){
Session session = this.getSession();
Connection con = null;
Statement stmt = null;

try{
con = session.connection();
stmt= con.createStatement();

stmt.executeUpdate("update form set " +
"LASTANSWERCOUNT=ANSWERCOUNT" +
"") ;
}catch(Exception e){
e.printStackTrace() ;
}finally{
if(stmt != null){
try{
stmt.close() ;
}catch(Exception e){
e.printStackTrace() ;
}
}
}
}
}

Full stack trace of any exception that occurs:
2007-03-27 17:24:42,596 INFO [org.hibernate.event.def.DefaultLoadEventListener] - Error performing load command
org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:91)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:79)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:307)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:109)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:105)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1561)
at org.hibernate.loader.Loader.doQuery(Loader.java:661)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1782)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:93)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:81)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2729)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:82)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:812)
at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:772)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:62)
at org.hibernate.Hibernate.initialize(Hibernate.java:292)
at cvi.epanel.util.cache.FormModelCache.reloadObj(FormModelCache.java:57)
at cvi.epanel.util.cache.BaseModelObjCache.getFromCache(BaseModelObjCache.java:156)
at cvi.epanel.service.spring.impl.AnswerServiceImpl.getFormById(AnswerServiceImpl.java:71)
at sun.reflect.GeneratedMethodAccessor133.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:335)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
at $Proxy13.getFormById(Unknown Source)
at cvi.epanel.webapp.struts.action.FormSurvey.execute(FormSurvey.java:83)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:106)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:75)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:292)
at cvi.epanel.security.acegi.intercept.web.EpanelFilterSecurityInterceptor.invoke(EpanelFilterSecurityInterceptor.java:91)
at cvi.epanel.security.acegi.intercept.web.EpanelSecurityEnforcementFilter.doFilter(EpanelSecurityEnforcementFilter.java:242)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:143)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at cvi.epanel.security.acegi.ui.EpanelAbstractProcessingFilter.doFilter(EpanelAbstractProcessingFilter.java:150)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:220)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:173)
at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:120)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:744)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:674)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:866)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool exhausted
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:103)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:80)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:304)
... 71 more
Caused by: java.util.NoSuchElementException: Timeout waiting for idle object
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:756)
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:95)
... 74 more
2007-03-27 17:24:42,595 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: null
2007-03-27 17:24:42,600 ERROR [org.hibernate.util.JDBCExceptionReporter] - Cannot get a connection, pool exhausted
2007-03-27 17:24:42,592 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: null
2007-03-27 17:24:42,600 ERROR [org.hibernate.util.JDBCExceptionReporter] - Cannot get a connection, pool exhausted
2007-03-27 17:24:42,600 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: null
2007-03-27 17:24:42,601 ERROR [org.hibernate.util.JDBCExceptionReporter] - Cannot get a connection, pool exhausted
2007-03-27 17:24:42,600 WARN [org.apache.struts.action.RequestProcessor] - Unhandled Exception thrown: class org.springframework.transaction.CannotCreateTransactionException

Name and version of the database you are using:
oracle 9.2
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?
as you see, I set the oracle database maxActive session number is 100,when the session number that used by my application reach 100,then the exception appear.At this time, I use sqlplus to select the number of active session,it's about 10 or much less,but the inactive session number is about 90 or more, the total number of the session is 100.
So I think this was caused by the application don't close the connection after it used the connection.
But I don't known if I should add the bellow code to close the connection after the application used it.

if(stmt!=null)
stmt.close();
if(con!=null)
con.close();
}

Besides, a few minites after the session number reach 100,the total session number is about 30.So I think the container does not reclaim the inactive connection until it over the maxtime.But why the container couldn't the connection when the application doesn't use is??

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject: Help me,please!
PostPosted: Thu Mar 29, 2007 5:21 am 
Newbie

Joined: Wed Mar 28, 2007 3:51 am
Posts: 2
I'm still confused about it.I need help.

Thanks for any help.


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.