From: <leg...@at...> - 2003-08-27 04:52:17
|
Message: The following issue has been closed. Resolver: Gavin King Date: Tue, 26 Aug 2003 11:51 PM I'm rejecting this because (a) you can work around this using DBCP connection validation (b) calling setAutocommit() is expensive for some (most?) DBs (c) this should really be addressed by patching the MySQL driver, NOT Hibernate! --------------------------------------------------------------------- View the issue: http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-184 Here is an overview of the issue: --------------------------------------------------------------------- Key: HB-184 Summary: Connection Timeout Exception using MySQL and DBCP Type: Patch Status: Closed Priority: Major Resolution: REJECTED Project: Hibernate2 Assignee: Reporter: Maarten Coene Created: Fri, 11 Jul 2003 9:21 AM Updated: Tue, 26 Aug 2003 11:51 PM Environment: Linux Description: Hi, The MySQL database closes by default it connections after 8 hours. If these connections are pooled, a "Connetion Timeout" exception will be thrown if you try to access the connection. The best way to solve this is to add ?autoReconnect=true to the jdbc url. But this doesn't work with Hibernate and DBCP. The reason is that this option only works if the autoCommit attribute is set to true and the DBCPConnectionProvider of Hibernate sets this to false by default. I've created a patch to fix this problem. thx Maarten Coene Index: DBCPConnectionProvider.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/connection/DBCPConnectionProvider.java,v retrieving revision 1.8 diff -u -r1.8 DBCPConnectionProvider.java --- DBCPConnectionProvider.java 25 Apr 2003 03:40:31 -0000 1.8 +++ DBCPConnectionProvider.java 11 Jul 2003 14:12:09 -0000 @@ -42,6 +42,7 @@ try { final Connection c = ds.getConnection(); if (isolation!=null) c.setTransactionIsolation( isolation.intValue() ); + c.setAutoCommit(false); return c; } catch (SQLException sqle) { @@ -56,6 +57,7 @@ public void closeConnection(Connection conn) throws SQLException { try { + conn.setAutoCommit(true); conn.close(); } catch (SQLException sqle) { @@ -119,7 +121,7 @@ // the "real" Connections created by the ConnectionFactory with // the classes that implement the pooling functionality. String validationQuery = props.getProperty(Environment.DBCP_VALIDATION_QUERY); - new PoolableConnectionFactory(connectionFactory, connectionPool, statementPool, validationQuery, false, false); + new PoolableConnectionFactory(connectionFactory, connectionPool, statementPool, validationQuery, false, true); // Finally, we create the PoolingDriver itself, // passing in the object pool we created. --------------------------------------------------------------------- JIRA INFORMATION: This message is automatically generated by JIRA. If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira |