I'm using iBatis for database access and frequently have problems with connections not being closed. Here is a copy of my sqlMapConfig file:
============================ <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd"> <sqlMapConfig> <properties resource="ibatis.properties" /> <settings lazyLoadingEnabled="true" cacheModelsEnabled="true" enhancementEnabled="false" useStatementNamespaces="false" /> <transactionManager type="JDBC" commitRequired="true"> <dataSource type="DBCP"> <property name="driverClassName" value="${driver}" /> <property name="url" value="${url}" /> <property name="username" value="${username}" /> <property name="password" value="${password}" /> <property name="maxActive" value="10"/> <property name="maxIdle" value="5"/> <property name="maxWait" value="5000"/> <property name="logAbandoned" value="true"/> <property name="removeAbandoned" value="true"/> <property name="removeAbandonedTimeout" value="1"/> <property name="Driver.logUnclosedConnections" value="true"/> </dataSource> </transactionManager> <sqlMap resource="job-sqlMap.xml" /> </sqlMapConfig> ============================ Due to the logAbandoned and removeAbandoned settings, I get a report in my log file whenever there is a connection that was not properly closed. Here is one of those log entries: 23:22:51.483 (10) Finalizing a Connection that was never closed: java.lang.Throwable: Connection was created at this point: at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:175) at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30) at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.java:24) at org.postgresql.Driver.makeConnection(Driver.java:393) at org.postgresql.Driver.connect(Driver.java:267) at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38) at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294) at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1148) at org.apache.commons.dbcp.AbandonedObjectPool.borrowObject(AbandonedObjectPool.java:84) at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:96) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880) at com.ibatis.sqlmap.engine.transaction.jdbc.JdbcTransaction.init(JdbcTransaction.java:48) at com.ibatis.sqlmap.engine.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:89) at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForList(MappedStatement.java:139) at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:567) at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:541) at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:118) at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImpl.java:94) at edu.calpoly.lib.multimedia.big.db.AutomaticPeriodUpdateIBatisImplDBHandler.getGamesWithAutomaticUpdatePolicy(AutomaticPeriodUpdateIBatisImplDBHandler.java:154) at edu.calpoly.lib.multimedia.big.game.AutoUpdateThread.run(AutoUpdateThread.java:155) The file: AutomaticPeriodUpdateIBatisImplDBHandler.java contains an iBatis call on line # 154: --> list = sqlMap.queryForList("getGamesWithAutoPolicy", null); from the map file: <select id="getGamesWithAutoPolicy" resultClass="java.util.HashMap"> <![CDATA[ SELECT gameid, policy FROM update_policy ]]> </select> Here is the code for the entire method that uses this transaction: ============================ public List getGamesWithAutomaticUpdatePolicy() throws BIGDatabaseFacadeException { List list = new ArrayList(); try { sqlMap.startTransaction(); list = sqlMap.queryForList("getGamesWithAutoPolicy", null); sqlMap.commitTransaction(); } catch(SQLException sqle) { throw new BIGDatabaseFacadeException(sqle); } finally { try { sqlMap.endTransaction(); } catch(SQLException sqle) { throw new BIGDatabaseFacadeException(sqle); } } return list; } ============================ I know that this could be handled as an automatic transaction, but I tried adding the start, commit and end transaction commands in my desperate attempt to fix this problem (but it still didn't help). Here is my code for creation of sqlMap - --> sqlMap = SqlMapClientBuilder.buildSqlMapClient(Resources.getResourceAsReader("sqlMaps.xml")); Except for the fact that occasionally connections are not closed, overall my database access using iBatis works very well. In the course of trying to fix this problem I've worked to update all my lib files to the latest versions, and here is current status: My iBatis lib file: ibatis-2.3.4.726.jar My JDBC driver: postgresql-8.4-701.jdbc3.jar Required commons files: commons-dbcp-1.2.2.jar commons-pool-1.5.3.jar Note that I tried adding --> commitRequired="true" to the transactionManager in sqlMaps.xml, hoping it might help, but no joy. Please help me figure out why my database connections often do not close. Thank you very much! -- View this message in context: http://www.nabble.com/Database-Connections-Not-Closing-tp25846239p25846239.html Sent from the iBATIS - User - Java mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
