Cannot change transaction read-only property in the middle of a transaction

為{幸葍}努か 提交于 2019-12-01 23:42:46

问题


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>

回答1:


I ran into this issue today. You might be missing one of the required dependencies of boneCP.

I was missing SLF4J library, and receiving the same message. Check whether you have the dependencies here: http://jolbox.com/index.html?page=http://jolbox.com/requirements.html




回答2:


I ran into the same issue and was able to solve it by doing these two steps:

  • setting the isolation level by adding these statement: config.setDefaultTransactionIsolation("READ UNCOMMITTED");

  • commit every transaction before closing.

I am not sure which one solved the problem or if both are necessary.



来源:https://stackoverflow.com/questions/15397840/cannot-change-transaction-read-only-property-in-the-middle-of-a-transaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!