Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hi guys,
Well for some reason it seems that i am using up all the connections, but i cant figure out why? This happens when the code i put bellow is runed through a few times. I must be leaving some connections open. But i cant figure out why?? When i am debugging i check and all the sessions are closed, and at the end i am closing the SessionFactory too. Am i doing anything wrong? PLEASE HELP!....going crazy here
thnx
Hibernate version:
Mapping documents:
Code between sessionFactory.openSession() and session.close():
public Team[] getTeamStandings() throws Exception
{
String ic = "in";
String ic_allias = ic;
String query1 = "SELECT team "
+ "FROM team IN CLASS hu.bme.iit.charalambos.modules.actions.portlets.Team "
+ "WHERE team.InChamp=:ic_allias";
Configuration cfg1 = new Configuration().addClass(Team.class);
SessionFactory sf1 = cfg1.buildSessionFactory();
Session sess1 = sf1.openSession();
List list1 = sess1.find(query1,ic, Hibernate.STRING);
Team[] TeamArray = new Team[list1.size()];
for(int i=0; i<=(list1.size()-1); i++)
{
TeamArray[i]=(Team)list1.get(i);
}
sess1.close();
String[] query = new String[list1.size()];
Configuration[] cfg = new Configuration[list1.size()];
//SessionFactory sf = new SessionFactory[list1.size()];
Session[] sess = new Session[list1.size()];
List[] list = new List[list1.size()];
for(int i=0; i<=list1.size()-1; i++)
{
String team_allias = TeamArray[i].getTeam_name();
query[i] = "SELECT matchup "
+ "FROM matchup IN CLASS hu.bme.iit.charalambos.modules.actions.portlets.Matchup "
+ "WHERE matchup.HTeam_name=:team_allias";
cfg[i] = new Configuration().addClass(Matchup.class);
sf1 = cfg[i].buildSessionFactory();
sess[i] = sf1.openSession();
list[i] = sess[i].find(query[i],TeamArray[i].getTeam_name(),Hibernate.STRING);
Matchup[] mup = new Matchup[list[i].size()];
for(int z=0; z<=list[i].size()-1; z++)
{
mup[z]=(Matchup) list[i].get(z);
if(mup[z].getResult().equals("1"))
{
TeamArray[i].setPoints(TeamArray[i].getPoints() + 3);
}
if(mup[z].getResult().equals("x"))
{
TeamArray[i].setPoints(TeamArray[i].getPoints() + 1);
}
}
sess[i].close();
}
String[] query2 = new String[list1.size()];
Configuration[] cfg2 = new Configuration[list1.size()];
//SessionFactory[] sf2 = new SessionFactory[list1.size()];
Session[] sess2 = new Session[list1.size()];
List[] list2 = new List[list1.size()];
for(int j=0; j<=list1.size()-1; j++)
{
String team_allias2 = TeamArray[j].getTeam_name();
query2[j] = "SELECT matchup "
+ "FROM matchup IN CLASS hu.bme.iit.charalambos.modules.actions.portlets.Matchup "
+ "WHERE matchup.ATeam_name=:team_allias2";
cfg2[j] = new Configuration().addClass(Matchup.class);
sf1 = cfg2[j].buildSessionFactory();
sess2[j] = sf1.openSession();
list2[j] = sess2[j].find(query2[j],TeamArray[j].getTeam_name(),Hibernate.STRING);
Matchup[] mup2 = new Matchup[list2[j].size()];
for(int z=0; z<=list2[j].size()-1; z++)
{
mup2[z]=(Matchup) list2[j].get(z);
if(mup2[z].getResult().equals("2"))
{
TeamArray[j].setPoints(TeamArray[j].getPoints() + 3);
}
if(mup2[z].getResult().equals("x"))
{
TeamArray[j].setPoints(TeamArray[j].getPoints() + 1);
}
}
sess2[j].close();
}
byPoints bp = new byPoints();
Arrays.sort(TeamArray,bp);
sf1.close();
return TeamArray;
}
Full stack trace of any exception that occurs:
Apr 21, 2005 1:25:12 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 1040, SQLState: 08004
Apr 21, 2005 1:25:12 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Data source rejected establishment of connection, message from server: "Too many connections"
Apr 21, 2005 1:25:12 PM net.sf.hibernate.JDBCException <init>
SEVERE: Cannot open connection
java.sql.SQLException: Data source rejected establishment of connection, message from server: "Too many connections"
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:649)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1782)
at com.mysql.jdbc.Connection.<init>(Connection.java:450)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at net.sf.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:101)
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:286)
at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3326)
at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3286)
at net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.java:65)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:779)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:265)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1521)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1517)
at hu.bme.iit.charalambos.modules.actions.portlets.Util.getArticles(Util.java:130)
at hu.bme.iit.charalambos.modules.actions.portlets.ViewArticlesAction.buildNormalContext(ViewArticlesAction.java:45)
at org.apache.jetspeed.modules.actions.portlets.VelocityPortletAction.buildNormalContext(VelocityPortletAction.java:74)
at org.apache.jetspeed.modules.actions.portlets.GenericMVCAction.doPerform(GenericMVCAction.java:169)
at org.apache.jetspeed.modules.actions.portlets.GenericMVCAction.perform(GenericMVCAction.java:76)
at org.apache.turbine.modules.ActionLoader.exec(ActionLoader.java:122)
at org.apache.jetspeed.portal.portlets.GenericMVCPortlet.buildContent(GenericMVCPortlet.java:276)
at org.apache.jetspeed.portal.portlets.GenericMVCPortlet.getContent(GenericMVCPortlet.java:207)
at org.apache.jetspeed.portal.security.portlets.PortletWrapper.getContent(PortletWrapper.java:119)
at sun.reflect.GeneratedMethodAccessor149.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:260)
at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:207)
at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:250)
at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:94)
at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:109)
at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:94)
at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:109)
at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:271)
at org.apache.velocity.Template.merge(Template.java:296)
at org.apache.velocity.app.Velocity.mergeTemplate(Velocity.java:492)
at org.apache.velocity.app.Velocity.mergeTemplate(Velocity.java:461)
at org.apache.turbine.services.velocity.TurbineVelocityService.decodeRequest(TurbineVelocityService.java:494)
at org.apache.turbine.services.velocity.TurbineVelocityService.handleRequest(TurbineVelocityService.java:336)
at org.apache.turbine.services.velocity.TurbineVelocity.handleRequest(TurbineVelocity.java:143)
at org.apache.jetspeed.portal.controls.VelocityPortletControl.getContent(VelocityPortletControl.java:155)
at sun.reflect.GeneratedMethodAccessor142.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:260)
at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:207)
at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:250)
at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:94)
at org.apache.velocity.runtime.directive.Foreach.render(Foreach.java:344)
at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:153)
at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:94)
at org.apache.velocity.runtime.directive.Foreach.render(Foreach.java:344)
at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:153)
at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:271)
at org.apache.velocity.Template.merge(Template.java:296)
at org.apache.velocity.app.Velocity.mergeTemplate(Velocity.java:492)
at org.apache.velocity.app.Velocity.mergeTemplate(Velocity.java:461)
at org.apache.turbine.services.velocity.TurbineVelocityService.decodeRequest(TurbineVelocityService.java:494)
at org.apache.turbine.services.velocity.TurbineVelocityService.handleRequest(TurbineVelocityService.java:336)
at org.apache.turbine.services.velocity.TurbineVelocity.handleRequest(TurbineVelocity.java:143)
at org.apache.jetspeed.portal.controllers.VelocityPortletController.getContent(VelocityPortletController.java:105)
at org.apache.jetspeed.portal.BasePortletSet.getContent(BasePortletSet.java:353)
at sun.reflect.GeneratedMethodAccessor165.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:260)
at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:207)
at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:250)
at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:271)
at org.apache.velocity.Template.merge(Template.java:296)
at org.apache.velocity.app.Velocity.mergeTemplate(Velocity.java:492)
at org.apache.velocity.app.Velocity.mergeTemplate(Velocity.java:461)
at org.apache.turbine.services.velocity.TurbineVelocityService.decodeRequest(TurbineVelocityService.java:494)
at org.apache.turbine.services.velocity.TurbineVelocityService.handleRequest(TurbineVelocityService.java:336)
at org.apache.turbine.services.velocity.TurbineVelocity.handleRequest(TurbineVelocity.java:143)
at org.apache.jetspeed.portal.controllers.VelocityPortletController.getContent(VelocityPortletController.java:105)
at org.apache.jetspeed.portal.BasePortletSet.getContent(BasePortletSet.java:353)
at sun.reflect.GeneratedMethodAccessor165.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:260)
at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:207)
at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:250)
at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:94)
at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:271)
at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:128)
at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:94)
at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:109)
at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:271)
at org.apache.velocity.Template.merge(Template.java:296)
at org.apache.velocity.app.Velocity.mergeTemplate(Velocity.java:492)
at org.apache.velocity.app.Velocity.mergeTemplate(Velocity.java:461)
at org.apache.turbine.services.velocity.TurbineVelocityService.decodeRequest(TurbineVelocityService.java:494)
at org.apache.turbine.services.velocity.TurbineVelocityService.handleRequest(TurbineVelocityService.java:336)
at org.apache.turbine.services.velocity.TurbineVelocity.handleRequest(TurbineVelocity.java:143)
at org.apache.jetspeed.portal.controls.VelocityPortletControl.getContent(VelocityPortletControl.java:155)
at org.apache.jetspeed.util.template.JetspeedTool.getPane(JetspeedTool.java:154)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:260)
at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:207)
at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:250)
at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:94)
at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:271)
at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:128)
at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:271)
at org.apache.velocity.Template.merge(Template.java:296)
at org.apache.velocity.app.Velocity.mergeTemplate(Velocity.java:492)
at org.apache.velocity.app.Velocity.mergeTemplate(Velocity.java:461)
at org.apache.turbine.services.velocity.TurbineVelocityService.decodeRequest(TurbineVelocityService.java:494)
at org.apache.turbine.services.velocity.TurbineVelocityService.handleRequest(TurbineVelocityService.java:336)
at org.apache.turbine.services.velocity.TurbineVelocity.handleRequest(TurbineVelocity.java:143)
at org.apache.turbine.modules.screens.VelocityDirectScreen.buildTemplate(VelocityDirectScreen.java:123)
at org.apache.turbine.modules.screens.TemplateScreen.doBuild(TemplateScreen.java:130)
at org.apache.turbine.modules.Screen.build(Screen.java:99)
at org.apache.turbine.modules.ScreenLoader.eval(ScreenLoader.java:129)
at org.apache.turbine.util.template.TemplateScreen.toString(TemplateScreen.java:126)
at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:321)
at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:271)
at org.apache.velocity.Template.merge(Template.java:296)
at org.apache.velocity.app.Velocity.mergeTemplate(Velocity.java:492)
at org.apache.velocity.app.Velocity.mergeTemplate(Velocity.java:461)
at org.apache.turbine.services.velocity.TurbineVelocityService.decodeRequest(TurbineVelocityService.java:494)
at org.apache.turbine.services.velocity.TurbineVelocityService.handleRequest(TurbineVelocityService.java:336)
at org.apache.turbine.services.velocity.TurbineVelocity.handleRequest(TurbineVelocity.java:143)
at org.apache.turbine.modules.layouts.VelocityDirectLayout.doBuild(VelocityDirectLayout.java:106)
at org.apache.turbine.modules.Layout.build(Layout.java:91)
at org.apache.turbine.modules.LayoutLoader.exec(LayoutLoader.java:123)
at org.apache.turbine.modules.pages.DefaultPage.doBuild(DefaultPage.java:169)
at org.apache.turbine.modules.Page.build(Page.java:90)
at org.apache.turbine.modules.PageLoader.exec(PageLoader.java:123)
at org.apache.turbine.Turbine.doGet(Turbine.java:563)
at org.apache.turbine.Turbine.doPost(Turbine.java:658)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: