0

我在 Grails 服务中有这个 Groovy 伪脚本:

sql.eachRow("""
 select id, col1, col2 
 from mytab
 where col1 is null or col2 is null
"""
){
 ... some code to produce c1, c2 here ...
 sql.execute("""
    update mytab
    set col1 = ${c1}, col2 = ${c2}
    where id = it.id
 """)
}

问题是更新仅在 eachRow 循环结束时提交给 DB。我想在 sql.execute 调用中准确提交更新。

我尝试在 sql.eachRow 之前插入 sql.resultSetConcurrency = GroovyResultSet.CONCUR_UPDATABLE,但更新仅在循环结束后继续提交。在 sql.execute() 之后也称为 sql.commit(),同样没有成功。

Sql 连接来自 DBCP Tomcat 数据源,访问 Oracle 8.1.7 数据库。

谢谢!

4

1 回答 1

0

默认情况下,Grails 服务方法调用会自动包装在事务中。如果抛出未经检查的 (!) 异常,则 db 事务将由底层 Spring 组件回滚。要禁用此行为,您必须使用@Transactional或指定static transactional = false如此处所述

于 2012-11-13T13:00:39.190 回答