sacred buffalo breath
Pennsylvania

Join sacred buffalo breath on tribe.net today!

sacred buffalo breath has invited you to join him at Tribe.net.

Problem with Hibernate, c3p0, mysql

topic posted Fri, October 28, 2005 - 12:04 AM by  Unsubscribed
Share/Save/Bookmark
Advertisement
I have a webapp that uses:
hibernate 3.0
the bundled c3p0 connection pool
mysql 4.1.11
on Debian Linux
under Resin 3.x

My problem:
When the webapp is deployed c3p0 creates the connection pool and everything works as expected. After about 12-24 hrs of leaving it running on a test server, i try to access the application again and get an error message that looks like the pool cannot get a connection. Below is the full stack trace:

java.sql.SQLException: Communication link failure: java.io.EOFException,
underlying cause: null

** BEGIN NESTED EXCEPTION **

java.io.EOFException

STACKTRACE:

java.io.EOFException
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1394)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1538)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1929)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2247)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1586)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:75)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:120)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1272)
at org.hibernate.loader.Loader.doQuery(Loader.java:391)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at mofobox.logic.UserManager.isValidUser(Unknown Source)
at mofobox.logic.UserManager.isValidUser(Unknown Source)
at mofobox.actions.LoginSubmitAction.execute(Unknown Source)
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.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:154)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:92)
at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:99)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:163)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:208)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:259)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:363)
at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:490)
at com.caucho.util.ThreadPool.run(ThreadPool.java:423)
at java.lang.Thread.run(Thread.java:595)


** END NESTED EXCEPTION **


at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1713)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1929)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2247)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1586)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:75)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:120)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1272)
at org.hibernate.loader.Loader.doQuery(Loader.java:391)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at mofobox.logic.UserManager.isValidUser(Unknown Source)
at mofobox.logic.UserManager.isValidUser(Unknown Source)
at mofobox.actions.LoginSubmitAction.execute(Unknown Source)
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.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:154)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:92)
at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:99)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:163)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:208)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:259)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:363)
at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:490)
at com.caucho.util.ThreadPool.run(ThreadPool.java:423)
at java.lang.Thread.run(Thread.java:595)




Relevant portions of my hibernate.cfg.xml are as follows:



<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://192.168.1.3/mp3</property>
<property name="connection.username">foo</property>
<property name="connection.password">bar</property>


<!-- c3p0 connection pool properties -->
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.max_statements">0</property>
<property name="hibernate.c3p0.idle_test_period">-1</property>
<property name="hibernate.c3p0.min_size">5</property>

I am also using the HibernateUtil code from the hibernate documentation:

public class SessionManager {

public static final SessionFactory sessionFactory;

static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}

public static final ThreadLocal sessionThreadLocal = new ThreadLocal();

public static Session currentSession() throws HibernateException {
Session s = (Session) sessionThreadLocal.get();
// Open a new Session, if this thread has none yet
if (s == null || (!s.isConnected())) {
s = sessionFactory.openSession();
// Store it in the ThreadLocal variable
sessionThreadLocal.set(s);
}
return s;
}

public static void closeSession() throws HibernateException {
Session s = (Session) sessionThreadLocal.get();
if (s != null)
s.close();
sessionThreadLocal.set(null);
}


If i redeploy the webapp everything works, for about a day, then the same problem.

Any ideas?
posted by:
Unsubscribed
Advertisement
Advertisement
  • Re: Problem with Hibernate, c3p0, mysql

    Mon, October 31, 2005 - 1:56 PM
    This problem has popped up multiple times in the Hibernate Users forum, so you're not alone. Here's a thread on it:

    forum.hibernate.org/viewtopic.php

    I think that the relevant parameters to fix this problem in your c3p0 config are maxIdleTime, idleConnectionTestPeriod, preferredTestQuery and testConnectionOnCheckout, depending on what approach you want to take. See:

    www.mchange.com/projects/c...nTestPeriod

    ...and related info on that page.
    • Unsu...
       

      Re: Problem with Hibernate, c3p0, mysql

      Thu, November 10, 2005 - 9:27 PM
      w00t!
      After a bit of testing and trying a few different suggestions provided in both links i have got this problem licked.

      Thanks Noah.
      • Re: Problem with Hibernate, c3p0, mysql

        Sat, March 18, 2006 - 10:33 AM
        Hi,

        I got tis problem some time ago and solved it with dbcp.
        Now I just migrated to hibernate 3 and I am getting that problem again.

        What config did you use to solve your problem ?

        My dbcp config is the following :

        <!--connection pool-->
        <property name="hibernate.dbcp.maxActive">10</property>
        <property name="hibernate.dbcp.whenExhaustedAction">1</property>
        <property name="hibernate.dbcp.maxWait">20000</property>
        <property name="hibernate.dbcp.maxIdle">10</property>

        <!-- prepared statement cache-->
        <property name="hibernate.dbcp.ps.maxActive">10</property>
        <property name="hibernate.dbcp.ps.whenExhaustedAction">1</property>
        <property name="hibernate.dbcp.ps.maxWait">20000</property>
        <property name="hibernate.dbcp.ps.maxIdle">10</property>

        <!-- optional query to validate pooled connections:-->
        <property name="hibernate.dbcp.validationQuery">select 1</property>
        <property name="hibernate.dbcp.testOnBorrow">true</property>
        <property name="hibernate.dbcp.testOnReturn">true</property>

        thanks

Recent topics in "Java Monkeys"

Topic Author Replies Last Post
Javascripting costs Schirin 3 May 17, 2007
Design patterns and principles emblylan 6 February 14, 2007
open source hosting alternatives? Mark 2 February 3, 2007
Ruby > Java Unsubscribed 6 January 9, 2007