本文介绍了可以简单地忽略Grails中的HeuristicCompletionException吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的grails应用程序中,我经常得到 org.springframework.transaction.HeuristicCompletionException:启发式完成:结果状态被回退;嵌套的异常是org.springframework.transaction.UnexpectedRollbackException:事务已回滚,因为已将其标记为仅回滚 .我以某种方式发现,当在@Transactional注释的方法内部发生任何类型的异常,并在具有自己的@Transactional的方法内部进行调用时,会发生这种情况.我的查询是可以简单地捕获并忽略此异常吗?

In my grails application i frequently get org.springframework.transaction.HeuristicCompletionException: Heuristic completion: outcome state is rolled back; nested exception is org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has been marked as rollback-only. I somehow found that this occurs when any kind of exception occurs inside a method annotated by @Transactional and called inside a method which has its own @Transactional. My Query is can this exception simply be caught and ignored?

推荐答案

正如Sudhir在评论中所建议的,我已经找到了解决方法,我可以在其中一种方法中复制启发式完成问题,并且发现不会回滚服务对现有交易的使用,我们按以下方法创建新交易:

I have got a workaround for this, as suggested by Sudhir in comments, i could replicate the Heuristic Completion issue in one of the methods and found that to not rollback the existing transaction use by the Service we create new transaction per method as :

@Transactional
Class MyService {
@Transactional(propagation = PROPAGATION.REQUIRES_NEW)
def myMethod(){
throw new Exception();
}
}

注释@Transactional(propagation = PROPAGATION.REQUIRES_NEW),这将为该方法创建一个新的Transaction,并暂停现有的事务.由于这将在每次执行该方法时创建新事务,这对于大型多线程应用程序绝对是性能问题,因此我通过处理服务类内部每个方法中的所有可能异常来缓解此问题.这样会更好.

annotating @Transactional(propagation = PROPAGATION.REQUIRES_NEW) this would create a new Transaction for the method and suspend the existing transaction. Since this would create new transaction each time the method executes which would definitely be a performance issue for huge multithreaded application so i mitigated this by handling all probable exceptions in each of the methods inside the service class. This would be better.

这篇关于可以简单地忽略Grails中的HeuristicCompletionException吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 01:22