I am using BoneCP with Postgresql and Spring JdbcTemplate. When JdbcTemplate executes query and then tries to close the connection, it gets this exception:
org.postgresql.util.PSQLException: Cannot change transaction read-only property in the middle of a transaction. at org.postgresql.jdbc2.AbstractJdbc2Connection.setReadOnly(AbstractJdbc2Connection.java:725) at com.jolbox.bonecp.ConnectionHandle.setReadOnly(ConnectionHandle.java:1279) at com.jolbox.bonecp.ConnectionHandle.(ConnectionHandle.java:254) at com.jolbox.bonecp.ConnectionHandle.recreateConnectionHandle(ConnectionHandle.java:273) at com.jolbox.bonecp.ConnectionHandle.close(ConnectionHandle.java:476) at org.springframework.jdbc.datasource.DataSourceUtils.doCloseConnection(DataSourceUtils.java:341) at org.springframework.jdbc.datasource.DataSourceUtils.doReleaseConnection(DataSourceUtils.java:328) at org.springframework.jdbc.datasource.DataSourceUtils.releaseConnection(DataSourceUtils.java:294) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:411) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:456) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:464) at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:472) at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:477)
Since it can't close connections, open connections reaches to max connection number, then app become unresponsive.
I am not setting any transaction related properties. So transaction settings should be default. How can I fix this?
Dependencies and configuration:
bonecp 0.8.0-rc1 postgresql 9.2-1002.jdbc4 spring-jdbc 3.2.1.RELEASE
<bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close"> <property name="driverClass" value="org.postgresql.Driver" /> <property name="jdbcUrl" value="jdbc:postgresql://127.0.0.1/mkayman" /> <property name="username" value="mkayman" /> <property name="password" value="" /> <property name="idleConnectionTestPeriodInMinutes" value="5" /> <property name="idleMaxAgeInMinutes" value="30" /> <property name="maxConnectionsPerPartition" value="5" /> <property name="minConnectionsPerPartition" value="2" /> <property name="partitionCount" value="2" /> <property name="acquireIncrement" value="1" /> <property name="statementsCacheSize" value="100" /> </bean>