简体   繁体   English

一组服务方法的一个事务-用于回滚Spring和Hibernate

[英]One Transaction for a set of service methods -for Rollback Spring and Hibernate

I have a set of service methods which has various DAO save operations.Currently my transaction advice is at service level.How would i set transaction advice to rollback the entire service methods if there is any exception in any of them. 我有一套服务方法,其中包含各种DAO保存操作。当前我的交易建议处于服务级别。如果其中任何异常,我将如何设置交易建议以回滚整个服务方法。

    <tx:method name="saveMethod1" propagation="REQUIRED"
            rollback-for="com.demo.CustomException" />

I cannot have all this saveMethod1,saveMethod2,saveMethod3 operations in one single method as there is some other logic needs to be done . 我不能在一个方法中拥有所有的saveMethod1,saveMethod2,saveMethod3操作,因为还需要执行其他一些逻辑。

The easiest way would be to make a new service that has one method that calls all the DAOs. 最简单的方法是制作一种具有调用所有DAO的方法的新服务。 But if you need other logic from the existing methods then the alternative is to wrap the existing service method calls in a method (of another service, so you are calling public methods through the proxies) and make that transactional. 但是,如果您需要现有方法中的其他逻辑,则替代方法是将现有服务方法调用包装在(另一个服务的方法中,因此您要通过代理来调用公共方法)并使该事务具有事务性。 The methods being called would have to have their transaction propagation set to REQUIRES so that they can participate in the transaction instated by the wrapping method. 被调用的方法必须将其事务传播设置为REQUIRES,以便它们可以参与包装方法发起的事务。 Since this is what you have specified anyway there shouldn't be a problem. 既然这是您所指定的,那应该没有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM