I cannot figure out how to specify default transaction isolation level in Grails application . Please help and point where my mistake is. Following are the details.
Grails: 1.3.7
Database: Sql Server 2008.
DataSource.groovy:
dataSource {
...
driverClassName = "net.sourceforge.jtds.jdbc.Driver"
dialect = org.hibernate.dialect.SQLServerDialect
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_UNCOMMITTED
}
hibernate {
...
connection.isolation = java.sql.Connection.TRANSACTION_READ_UNCOMMITTED
}
Then I'm navigating through the application and execute the following query at the same time:
SELECT session_id, host_name, program_name, login_name, status, transaction_isolation_level
FROM sys.dm_exec_sessions
WHERE host_name IS NOT NULL AND login_name = 'cm'
ORDER BY host_name, program_name
that returns:
session_id host_name program_name login_name status transaction_isolation_level
61 ANDREYK-WS jTDS cm running 2
2 means READ_COMMITTED. I expect to see 1, i.e. READ_UNCOMMITTED.
If I explicitly specify: @Transactional(isolation=Isolation.READ_UNCOMMITTED)
The query above returns 1 as expected. However I do not want to attribute all the services in my application. What am I missing?
Transaction Isolation Levels The default isolation level is REPEATABLE READ . Other permitted values are READ COMMITTED , READ UNCOMMITTED , and SERIALIZABLE .
Isolation Level: ReadCommitted The isolation level ReadCommitted is usually the default one.
The database isolation level specifies the degree to which your program is isolated from the concurrent actions of other programs. The default isolation level for all ANSI-compliant databases is Repeatable Read.
The isolation level of the transactional support is default to READ UNCOMMITTED. You can change it to READ COMMITTED SNAPSHOT ISOLATION by turning ON the READ_COMMITTED_SNAPSHOT database option for a user database when connected to the master database.
This needs to be set under the properties attribute of the datasource configuration i.e.
dataSource {
...
driverClassName = "net.sourceforge.jtds.jdbc.Driver".
dialect = org.hibernate.dialect.SQLServerDialect
properties {
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_UNCOMMITTED.
}
}
I have a bit of a variation of this as I have multiple DS
At the top of your datasources define a shared map of properties (tune this to your environment):
def defaultConnectionProperties = [
maxActive: 50,
maxIdle: 25,
minIdle: 5,
initialSize: 5,
minEvictableIdleTimeMillis: 60000,
timeBetweenEvictionRunsMillis: 60000,
maxWait: 10000,
defaultTransactionIsolation: java.sql.Connection.TRANSACTION_READ_UNCOMMITTED
]
Then each DS is something like:
dataSource {
pooled = true
driverClassName = "net.sourceforge.jtds.jdbc.Driver"
// driverClassName = "com.p6spy.engine.spy.P6SpyDriver" // use this driver to enable p6spy logging
//readOnly = "true"
properties = defaultConnectionProperties
}
Restart your Grails app.
The wierd thing is I see the initial transaction_isolation_level = 2, but when I actually hit the DB the connection properties seem to be set and it flicks to a 1.
Also you can inspect: grailsApplication.config and look for the datasources and confirm the settings there
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With