【发布时间】:2013-07-09 16:09:03
【问题描述】:
我有机器和零件域类
在我的服务类中,我试图启动一个事务,在该事务中我想创建一个新事务并在它从内部事务中出来时提交它。
Machine.withTransaction { // transaction 1
// some code to add Parts
// some code to remove Parts
Machine.withNewTrasaction { // transaction 2
// some code to remove Parts.
} // end of transaction 2
// some code to update couple of columns in machine table.
}// end of transaction 1
当它来自transaction 2 时,我希望transaction 2 被提交给机器的零件,而不考虑transaction 1。但是grails 将错误返回为"Illegal attempt to associate a collection with two open sessions"
如何单独提交transaction 2而不考虑transaction 1?
【问题讨论】:
-
你可以试试
Machine.withNewTransaction(propagation: TransactionDefinition.PROPAGATION_REQUIRES_NEW){...}吗? -
@dmahapatro 我收到错误,因为
No signature of method : Machine.withNewTransaction我觉得语法或有问题。我也找不到很好的文档
标签: grails transactions