2

如果我将存储过程的 sql 调用放在Grails GORM中withTransaction,是否会使用相同的连接?例如:groovy.sql.SqlwithTransaction

可以说我有一个命令:

@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')
    }
  }

}
4

1 回答 1

2

我已经找到了如何做到这一点。

def sessionFactory

//after GORM saves...  
sessionFactory.currentSession.flush()
Sql s = new Sql( sessionFactory.currentSession.connection()  )
s.call()

本主题中的更多信息。

于 2012-04-19T20:34:39.330 回答