如果我将存储过程的 sql 调用放在 withTransaction
中,
Grails GORM withTransaction
和 groovy.sql.Sql
将使用相同的连接?例如:
假设我有一个命令:
@Validateable
class MyCommand {
List<MyModel> listOfModel
}
然后我有一个服务来处理这个命令
class MyService {
def dataSource
def handleCommand( MyCommand command ) {
MyModel.withTransaction { status ->
for( MyModel m : command.listOfModel ) {
if( !m.save() ) {
status.setRollbackOnly()
throw new MyException(m.errors)
}
}
//now I need to call a stored proc. This will use the same connection?
//withTransaction will commit the call?
Sql s = new Sql(dataSource)
s.call('my_stored_proc')
}
}
}
最佳答案
我已经找到了如何做到这一点。
def sessionFactory
//after GORM saves...
sessionFactory.currentSession.flush()
Sql s = new Sql( sessionFactory.currentSession.connection() )
s.call()
更多信息请参见 this topic .
关于java - Grails:groovy.sql.Sql 和 Model.withTransaction 会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10235210/