-->
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.  [ 4 posts ] 
Author Message
 Post subject: hibernate/c3p0 reovery after db crash
PostPosted: Thu Jun 10, 2004 7:31 pm 
Newbie

Joined: Thu Jun 10, 2004 6:04 pm
Posts: 8
Hi,

Is Hibernate (or its pool) supposed to handle a database crash? Am I am supposed to handle a database crash if it happens when I get the connection from hibernate's session? I don't really see a way to tell hibernate to have its connection pool destroy a connection.

I'm using Hibernate 2.1.4 connecting to an oracle9i db via c3p0, and I'm using a session in a servlet like this:
Code:
doPost() {
  Session aSession = null;
 
  try {
    aSession = mySessionFactory.openSession();
    [...]

    Statement aStatement = aSession.connection();
    [...]
  } finally {
    aSession.close();
  }
}


After a db crash, on .connection(), I get a big stack trace (I've pared out the tomcat parts with [...]):

Code:
14:26:19,713  WARN - SQL Error: 0, SQLState: null
14:26:19,713 ERROR - com.mchange.v2.resourcepool.ResourcePoolException: Attempted to use a closed or broken resource pool
        at com.mchange.v2.resourcepool.BasicResourcePool.ensureNotBroken(BasicResourcePool.java:920)
        at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:191)
        at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:170)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:172)
        at com.mchange.v2.c3p0.PoolBackedDataSource.getConnection(PoolBackedDataSource.java:58)
        at net.sf.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:33)
        at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:278)
        at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3302)
        at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3282)
        at MyServlet.doPost(MyServlet.java)
        [...]
14:26:19,714 ERROR - Cannot open connection
java.sql.SQLException: com.mchange.v2.resourcepool.ResourcePoolException: Attempted to use a closed or broken resource pool
        at com.mchange.v2.resourcepool.BasicResourcePool.ensureNotBroken(BasicResourcePool.java:920)
        at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:191)
        at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:170)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:172)
        at com.mchange.v2.c3p0.PoolBackedDataSource.getConnection(PoolBackedDataSource.java:58)
        at net.sf.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:33)
        at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:278)
        at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3302)
        at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3282)
        at MyServlet.doPost(MyServlet.java)
        [...]

        at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:62)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:174)
        at com.mchange.v2.c3p0.PoolBackedDataSource.getConnection(PoolBackedDataSource.java:58)
        at net.sf.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:33)
        at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:278)
        at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3302)
        at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3282)
        at MyServlet.doPost(MyServlet.java)
        [...]


I hope someone can point me in the right direction.

Much thanks,
Zac.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 7:09 pm 
Newbie

Joined: Thu Jun 10, 2004 6:04 pm
Posts: 8
Unfortunately I cannot shut down my database do more testing (others use it) so it's difficult to collect verbose logs. While I'm sure the loggs would help, can't get them right now, yet need to know what I should be doing to allow hibernate to recover from this situation.

The only place I can find that shuts down the ConnectionProvider is the SessionFactoryImpl. The shutting down of the ConnectionProvider is where c3p0's BasicResourcePool is closed, which is something that must happen before c3p0 will send "Attempted to use a closed or broken resource pool".

It would seem that a SessionFactory gets closed on a connection error; how can I re-initialize it so my app can recover from a db crash?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 15, 2004 5:07 pm 
Newbie

Joined: Thu Jun 10, 2004 6:04 pm
Posts: 8
Well, I finally got some access to my server, and I don't see this problem when I use tomcat's Datasource instead of c3p0. There doesn't appear to be enough difference between the C3P0ConnectionProvider and the DatasourceConnectionProvider to account for the behaviour difference, so I believe this issue is with C3P0 itself rather than with how Hibernate uses it.

Cheers,
Zac.


Top
 Profile  
 
 Post subject: work-around?
PostPosted: Wed Jun 16, 2004 8:22 pm 
Newbie

Joined: Thu Jun 10, 2004 6:04 pm
Posts: 8
This is indeed an issue with c3p0 0.8.4.5 and can be addressed by making the following adjustment to that library:

Edit: com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool
- Change the value of ACQ_RETRY_ATTEMPTS to 0
Rebuild.

My testing indicates that with this change, my call to Session.connection() blocks until the database is available... interesting behaviour, perhaps better than having to restart the application.


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