简体   繁体   English

在春季声明式事务管理中,提交事务时

[英]In spring declarative transaction management when transaction commited

As describe in question , where actually transaction get committed in spring desclarative transaction mangament. 如所描述的,春季声明式交易管理中实际执行的交易。 For eg suppose i have following code 例如,假设我有以下代码

@Service
@Transactional
class CustomerAService{
    public void processCustomer(Customer customer){
        //call dao and insert customer
        furtherProcessCustomer(Customer customer);
        //last line (a)
    }

    @Transactional(propagation=Propagation.REQUIRES_NEW)
    public void furtherProcessCustomer(Customer customer){
        //call another dao do some db work

        //last line (b)
    }
}

suppose if i stop execution @ line //last line (a) so will trasaction get commited for processCustomer() method. 假设如果我停止执行@行//最后一行(a),那么会为processCustomer()方法提交事务。 I tried to search on net but didn't get much information 我试图在网上搜索,但没有得到太多信息

The transaction management in spring occurs via aspect-oriented-programming (AOP) proxy objects. 春天的事务管理是通过面向方面的编程(AOP)代理对象进行的。 This means that the method must return cleanly in order for the transaction to be committed. 这意味着该方法必须干净地返回以便提交事务。 Your code is "Target Method" in the diagram below, while the transactions are committed in the "Transaction Advisor". 下图中的代码是“目标方法”,而事务是在“事务顾问”中提交的。 More documentation here. 此处有更多文档。

AOP交易处理

Your example is kind of subtle since furtherProcessCustomer method is called from inside the same class, which will not be called via the AOP proxy object and therefore your @Transactional(propagation=Propagation.REQUIRES_NEW) will not be used. 您的示例有点微妙,因为在同一类内部调用了furtherProcessCustomer方法,该方法不会通过AOP代理对象进行调用,因此不会使用@Transactional(propagation=Propagation.REQUIRES_NEW)

If you had another service, also with @Transactional annotations and then you called furtherProcessCustomer , this would occur via the AOP Proxy object and you would therefore have a nested transaction. 如果您还有另一个服务(也带有@Transactional批注),然后又调用了furtherProcessCustomer ,则这将通过AOP代理对象发生,因此将具有嵌套事务。

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

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