ChainedTransaction Manager 抛出 HeuristicCompletionException 而不是 Rollback [英] ChainedTransaction Manager throws HeuristicCompletionException and not Rollback

查看:29
本文介绍了ChainedTransaction Manager 抛出 HeuristicCompletionException 而不是 Rollback的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 chainedTransactionManager 和两个不同的数据源.我的问题是 MydataSource1 实体在 database.Mydatasource1.save 工作中有一个唯一的约束冲突,然后它传递给 mydatasource2.save 然后它抛出 HeuristicCompletionException 和 mydatasource2.save 工作而不是回滚.什么如果发生任何类型的异常,我想无条件回滚

I have chainedTransactionManager and two different datasources.My problem is MydataSource1 entity has a unique constraint violation in database.Mydatasource1.save work then it pass to mydatasource2.save and then it throws HeuristicCompletionException and mydatasource2.save work and not rollback.What I want rollback without any condition if any kind of exceptions occurs

> org.springframework.transaction.HeuristicCompletionException:
> Heuristic completion: outcome state is mixed; nested exception is
> org.springframework.dao.DataIntegrityViolationException: could not
> execute statement; SQL [n/a]; constraint [MYSchema.UNIQUE_NAME]; nested
> exception is org.hibernate.exception.ConstraintViolationException:
> could not execute statement\r\n\tat
> org.springframework.data.transaction.ChainedTransactionManager.commit(ChainedTransactionManager.java:177)\r\n\tat
> org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:619)\r\n\tat
> org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:372)\r\n\tat

@Transactional(rollbackFor = {Exception.class,Throwable.class}, isolation = Isolation.READ_COMMITTED, transactionManager = "MychainedTransactionManager", propagation = Propagation.REQUIRED)
        public void saveMultipleDBSource() 
    {
    ...........
    MyDataSource1.Save(Entity1)
    
    MyDataSource2.Save(Entity2)
    
    }

推荐答案

解决方法_1:

这里是一个尝试和测试类似的场景,看起来进行分析、讨论和讨论已经解决了我建议你,试试这个 &遍历整个线程,这与您的情况类似.目前,您获得了一个状态:STATE_MIXED 而他获得了一个状态:STATE_ROLLED_BACK

Here, is a tried and tested similar scenario that seems to be analyzed, discussed & solved already I'd suggest you, give this a try & go through the entire thread, which is a similar scenario of yours. Currently, you are getting a state: STATE_MIXED whereas he had got a state: STATE_ROLLED_BACK

解决方法_2:

您还可以围绕目标区域进行异常处理,因为您得到的异常是未经检查的异常.由于您的要求很明确,如果您只想优雅地回滚,那么您可以尝试使用此 spring 文档链接.

You can also work on exception handling around your target area since the exception you're getting is an unchecked exception. As your requirement is clear, if you just want to rollback gracefully then you can try doing the exception handling for this scenario using this spring documentation link.

我希望,这会以某种方式帮助您.谢谢.:)

I Hope, this helps you somehow or the other. Thank you. :)

这篇关于ChainedTransaction Manager 抛出 HeuristicCompletionException 而不是 Rollback的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆