views:

123

answers:

2

Hi,

is it possible to open a JdbcTemplate connection in read only mode, so that I can't perform any changes to the underlying data source?

+1  A: 

I don't believe the JDBC connection API allows this.

You have two choices:

  1. GRANT appropriate permissions on the database level to only allow SELECT operations;
  2. Use Spring AOP and Security to intercept calls to write operations on the DAO and forbid them for certain roles.

The second choice is obviously more flexible and in the spirit of Spring's natural idiom.

duffymo
+1  A: 

Use Spring Transactions and declare the transaction as readOnly. See http://static.springsource.org/spring/docs/2.5.6/reference/transaction.html#transaction-declarative-annotations

gpeche