如何在Grails中指定默认事务隔离级别

如何在Grails中指定默认事务隔离级别

本文介绍了如何在Grails中指定默认事务隔离级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚如何在Grails应用程序中指定默认的事务隔离级别。请帮助并指出我的错误所在。以下是详细信息。



Grails:1.3.7



数据库: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
}

然后我浏览应用程序并同时执行以下查询:

  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

返回:

  session_id host_name pro gram_name login_name status transaction_isolation_level 
61 ANDREYK -WS jTDS cm运行2



表示READ_COMMITTED。我希望看到1,即READ_UNCOMMITTED。



如果我明确指定:
@Transactional(isolation = Isolation.READ_UNCOMMITTED)

上面的查询按预期返回1。
但是我不想在我的应用程序中引用所有的服务。
我缺少什么?

解决方案

这需要在即

  dataSource {
...
driverClassName =net.sourceforge.jtds.jdbc.Driver。
dialect = org.hibernate.dialect.SQLServerDialect
properties {
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_UNCOMMITTED。
}
}


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?

解决方案

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.
  }
}

这篇关于如何在Grails中指定默认事务隔离级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 20:19