小编imr*_*ran的帖子

实现声明性事务的问题

我想在功能级别实现事务控制.我想要的是这样的.

class MyService {

static transactional = false

@Transactional(readOnly = false,propagation = Propagation.REQUIRES_NEW)

public def saveCountry(){Country co = new Country(name:'mycountry')co.save()createState()

}

@Transactional(readOnly = false,propagation = Propagation.REQUIRES_NEW)

public def createState(){State state = new State(name:'state')state.save()throw new RuntimeException()}}

我想要的是createState()创建一个独立于saveCountry()的新事务,这样如果createState()失败,

已保存的国家/地区对象未被撤销.虽然我已经给出了注释,但它们没有产生预期的效果.此处创建单个事务,并在抛出异常时撤消该事务.保存对象的任何一个.

任何人都可以帮忙

grails transactions declarative

6
推荐指数
1
解决办法
233
查看次数

标签 统计

declarative ×1

grails ×1

transactions ×1