-->
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.  [ 3 posts ] 
Author Message
 Post subject: db connection won't reopen after being idle for a day
PostPosted: Fri Jul 30, 2010 4:42 am 
Newbie

Joined: Sun May 17, 2009 5:46 pm
Posts: 8
After my tomcat server has been running successfully for a day I get the below stacktrace. All the forums I've read say that the solution is just to configure c3p0, but I thought I had. i.e. This is my hibernate.cfg.xml file:

<!DOCTYPE hibernate-configuration SYSTEM "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/togetherdining</property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.connection.password">pass</property>
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>

<!-- Use the C3P0 connection pool provider -->
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>

<!-- Show and print nice SQL on stdout -->
<property name="show_sql">true</property>
<property name="format_sql">true</property>

<!-- List of XML mapping files -->
<mapping resource="com/togetherdining/db/beans/togetherdining.hbm.xml"/>
</session-factory>
</hibernate-configuration>

What else do I need to do? What check can I make?

StackTrace:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Connection.close() has already been called. Invalid operation in this state.
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
java.lang.reflect.Constructor.newInstance(Constructor.java:513)
com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
com.mysql.jdbc.Util.getInstance(Util.java:381)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
com.mysql.jdbc.ConnectionImpl.getMutex(ConnectionImpl.java:3117)
com.mysql.jdbc.ConnectionImpl.rollback(ConnectionImpl.java:4726)
org.hibernate.transaction.JDBCTransaction.rollbackAndResetAutoCommit(JDBCTransaction.java:217)
org.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:196)
com.togetherdining.util.HibernateUtil.handleError(HibernateUtil.java:37)
com.togetherdining.tags.infra.DBTagBase.processStartTag(DBTagBase.java:38)
com.togetherdining.tags.infra.TagBase.doStartTag(TagBase.java:24)
org.apache.jsp.planDinner_jsp._jspService(planDinner_jsp.java:164)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


Thanks in advance. I hope somebody can help.


Top
 Profile  
 
 Post subject: Re: db connection won't reopen after being idle for a day
PostPosted: Sat Jul 31, 2010 7:59 am 
Newbie

Joined: Sun May 17, 2009 5:46 pm
Posts: 8
Ok, I've noticed this in my logs:

[main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)

so obviously it's not actually using c3p0. Anybody know what more I need to do to make it use c3p0?


Top
 Profile  
 
 Post subject: Re: db connection won't reopen after being idle for a day
PostPosted: Sat Jul 31, 2010 10:02 am 
Newbie

Joined: Sun May 17, 2009 5:46 pm
Posts: 8
Got it!

I downloaded the hibernate sourcecode and after some debugging in the ConnectionProviderFactory, turns out that the logic that sets up the C3P0ConnectionProvider wasn't added until hibernate 3.5.*, and I'm using 3.3.1 (woops).

Two solutions:
1. upgrade to the latest hibernate
2. Add this hibernate property to tell hibernate which provider to use:
hibernate.connection.provider_class = org.hibernate.connection.C3P0ConnectionProvider

I've gone with (2) for now to avoid the risk of anything else breaking.


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