If I understand correctly, Spring would be able to close the database connections on the background after the usage, there is no need to explicitly returning the connection to the pool. But I got the following error when the following code was executed multiple times from webpage (when I declared to have initial connection of 5, this problem will happen on the 6th submission of the webpage) :
try {
session = getSession();
List users = session.createCriteria(User.class).add(
Expression.eq(keyField, name)).list();
if ((users == null) || (users.size() == 0))
return null;
return (User)users.get(0);
}
catch(Exception e) {
throw new DataRetrievalFailureException("system.error.hibern ate", e);
}
This method is defined to be transactional.
org.springframework.dao.DataRetrievalFailureExcept ion: system.error.hibernate; nested exception is org.hibernate.exception.GenericJDBCException: Cannot open connection org.hibernate.exception.GenericJDBCException: Cannot open connection at org.hibernate.exception.ErrorCodeConverter.handled NonSpecificException(ErrorCodeConverter.java:92) at org.hibernate.exception.ErrorCodeConverter.convert (ErrorCodeConverter.java:80) at org.hibernate.exception.JDBCExceptionHelper.conver t(JDBCExceptionHelper.java:43) at org.hibernate.exception.JDBCExceptionHelper.conver t(JDBCExceptionHelper.java:29) at org.hibernate.jdbc.AbstractBatcher.openConnection( AbstractBatcher.java:384) at org.hibernate.jdbc.JDBCContext.connect(JDBCContext .java:141) at org.hibernate.jdbc.JDBCContext.connection(JDBCCont ext.java:88) at org.hibernate.jdbc.AbstractBatcher.prepareQuerySta tement(AbstractBatcher.java:85) at org.hibernate.loader.Loader.prepareQueryStatement( Loader.java:1090) at org.hibernate.loader.Loader.doQuery(Loader.java:36 2) at org.hibernate.loader.Loader.doQueryAndInitializeNo nLazyCollections(Loader.java:203) at org.hibernate.loader.Loader.doList(Loader.java:149 9) at org.hibernate.loader.Loader.list(Loader.java:1482) at org.hibernate.loader.criteria.CriteriaLoader.list( CriteriaLoader.java:111) at org.hibernate.impl.SessionImpl.list(SessionImpl.ja va:1246) at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl. java:299) at com.lunchbox.domain.dao.hibernate.UserDAOImpl.getU ser(UserDAOImpl.java:58) at com.lunchbox.service.UserFacadeImpl.getInfoByUserN ame(UserFacadeImpl.java:65) at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:310) at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:163) at $Proxy0.getVideoByActorName(Unknown Source) at ca.videobox.ui.bean.SearchVideoPage.search(SearchV ideoPage.java:125) at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at com.sun.faces.el.MethodBindingImpl.invoke(MethodBi ndingImpl.java:126) at com.sun.faces.application.ActionListenerImpl.proce ssAction(ActionListenerImpl.java:72) at javax.faces.component.UICommand.broadcast(UIComman d.java:312) at javax.faces.component.UIViewRoot.broadcastEvents(U IViewRoot.java:267) at javax.faces.component.UIViewRoot.processApplicatio n(UIViewRoot.java:381) at com.sun.faces.lifecycle.InvokeApplicationPhase.exe cute(InvokeApplicationPhase.java:75) at com.sun.faces.lifecycle.LifecycleImpl.phase(Lifecy cleImpl.java:200) at com.sun.faces.lifecycle.LifecycleImpl.execute(Life cycleImpl.java:90) at javax.faces.webapp.FacesServlet.service(FacesServl et.java:197) at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:173) at net.sf.acegisecurity.util.FilterChainProxy$Virtual FilterChain.doFilter(FilterChainProxy.java:300) at net.sf.acegisecurity.intercept.web.FilterSecurityI nterceptor.invoke(FilterSecurityInterceptor.java:8 4) at net.sf.acegisecurity.intercept.web.SecurityEnforce mentFilter.doFilter(SecurityEnforcementFilter.java :181) at net.sf.acegisecurity.util.FilterChainProxy$Virtual FilterChain.doFilter(FilterChainProxy.java:311) at net.sf.acegisecurity.ui.basicauth.BasicProcessingF ilter.doFilter(BasicProcessingFilter.java:212) at net.sf.acegisecurity.util.FilterChainProxy$Virtual FilterChain.doFilter(FilterChainProxy.java:311) at net.sf.acegisecurity.ui.AbstractProcessingFilter.d oFilter(AbstractProcessingFilter.java:372) at net.sf.acegisecurity.util.FilterChainProxy$Virtual FilterChain.doFilter(FilterChainProxy.java:311) at net.sf.acegisecurity.context.HttpSessionContextInt egrationFilter.doFilter(HttpSessionContextIntegrat ionFilter.java:217) at net.sf.acegisecurity.util.FilterChainProxy$Virtual FilterChain.doFilter(FilterChainProxy.java:311) at net.sf.acegisecurity.util.FilterChainProxy.doFilte r(FilterChainProxy.java:179) at net.sf.acegisecurity.util.FilterToBeanProxy.doFilt er(FilterToBeanProxy.java:125) at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:173) at de.mindmatters.faces.spring.RequestHandledFilter.d oFilter(RequestHandledFilter.java:117) at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:214) at org.apache.catalina.core.StandardContextValve.invo ke(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.invok e(StandardEngineValve.java:107) at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:148) at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:825) at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:738) at org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:526) at org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:80) at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:684) at java.lang.Thread.run(Thread.java:595) Caused by: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot get a connection, pool exhausted at org.apache.tomcat.dbcp.dbcp.PoolingDataSource.getC onnection(PoolingDataSource.java:103) at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getCon nection(BasicDataSource.java:540) at org.springframework.orm.hibernate3.LocalDataSource ConnectionProvider.getConnection(LocalDataSourceCo nnectionProvider.java:75) at org.hibernate.jdbc.AbstractBatcher.openConnection( AbstractBatcher.java:381) ... 65 more Caused by: java.util.NoSuchElementException: Timeout waiting for idle object at org.apache.tomcat.dbcp.pool.impl.GenericObjectPool .borrowObject(GenericObjectPool.java:756) at org.apache.tomcat.dbcp.dbcp.PoolingDataSource.getC onnection(PoolingDataSource.java:95) ... 68 more
I wonder how come the connections were not released after the method was finished executing? I am using Spring 1.2, Hibernate 3, JSF 1.1, acegi 0.8, JSF-Spring 2.7 and JDK5 running in Tomcat 5.5.7. Thanks in advance.


Reply With Quote