Feb 27, 2008

«Connection is read-only» Exception

I've ran into funny exception recently. I've a function updating database table using Spring's JdbcTemplate and for some reason there was this exception:

java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1056)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1973)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1940)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1925)
at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:101)
at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:773)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:566)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:767)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:825)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:833)
at com.myapplication.user.JdbcUserDao.saveData(JdbcUserDao.java:511)

...


There wasn't much about it on the Internet, but apparently, the problem occures when the JdbcUserDao is configured as proxy bean and saveData method (or any other method making updates to database) is missing its PROPAGATION_REQUIRED flag in the applicationContext.xml.

No comments: