I have this Groovy pseudo-script in a Grails service:
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
""")
}
The problem is that updates are committed to DB only at the end of eachRow loop. I wanted to have updates committed exactly at sql.execute call.
I tried inserting
sql.resultSetConcurrency = GroovyResultSet.CONCUR_UPDATABLE
right before sql.eachRow, but the updates continue to commit only after the end of loop.
Also called an sql.commit() right after sql.execute(), again without success.
The Sql connection comes from a DBCP Tomcat datasource, accessing an Oracle 8.1.7 database.
Thank you!
Grails service method calls are, per default, automatically wrapped with a transaction. If an unchecked (!) exception is thrown, the db transaction will be rolled back by underlying Spring components. To disable this behaviour, you either have to use
@Transactionalor specifystatic transactional = false, as described here.