我可以在 withTransaction
内提交吗?关闭?我想在我的 Quartz
里面做这样的事情工作:
Author.withTransaction {
def author = Author.get(1)
author.staus = 'processing'
author.save()
commit // how can i do this?
// so some work here which takes 1-2 minutes
author.status = 'completed'
author.save()
}
这个想法是我想要一个状态屏幕来显示所有
Author
目前正在处理的 s,所以我想将状态设置为 processing
并且能够从 Controller 看到这个状态。编辑:
这将在没有
withTransaction
的情况下工作,但我必须有 withTransaction
那里...见this question .
最佳答案
为了从不同的未提交事务读取值,您的数据库隔离级别必须设置为“读取未提交”,这通常表明您可能做错了什么。
你有什么理由不能把它分成单独的交易吗?一种将记录标记为“进行中”,另一种用于执行实际工作?
Author.withTransaction {
def author = Author.get(id)
author.status = 'processing'
author.save()
}
Author.withTransaction() {
def author = Author.get(id)
// do some work
author.status = 'completed'
author.save()
}
关于hibernate - 我可以在 withTransaction 闭包内提交吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17713231/