简体   繁体   English

从非事务方法调用的多个事务方法的传播级别

[英]Propagation level for multiple transaction methods called from a non-transactional method

I was going through this article https://docs.spring.io/spring/docs/4.2.x/spring-framework-reference/html/transaction.html#tx-propagation 我正在浏览这篇文章https://docs.spring.io/spring/docs/4.2.x/spring-framework-reference/html/transaction.html#tx-propagation

I had a doubt regarding what happens when multiple @Transactional methods are called from a non-transactional method. 我对从非事务方法调用多个@Transactional方法会发生什么感到怀疑。

ADao.java
@Transactional(readOnly=true)
public A getA()

@Transactional
public A insertA()

AService.java
public void getAndInsertA() {
    aDao.getA();
    aDao.insertA();
}

Is my understanding correct when I say both these calls getA() and insertA() will be part of separate transactions? 当我说这两个调用getA()insertA()将成为单独事务的一部分时,我的理解是否正确?

Another question, is it possible that both the queries will use the same DB connection? 另一个问题,两个查询是否可能使用相同的数据库连接?

Yes, your queries are not in the same transaction. 是的,您的查询不在同一笔交易中。 If you want to, annotate your service with @Transactional. 如果需要,请使用@Transactional注释服务。

And maybe. 有可能。 You have a connection pool, you don't really know if your transactions will use the same connection. 您有一个连接池,您实际上并不知道您的事务是否将使用相同的连接。 But that's not really important, is it ? 但这不是很重要,不是吗?

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

相关问题 如何从事务方法调用非事务方法 - How to call non-transactional methods from a Transactional method 在另一个实例中从事务方法调用 spring 非事务方法时,事务是否得到传播? - When calling a spring Non-Transactional method from a Transactional Method in another instance, does the transaction get propagated? 事务回滚后调用非事务方法 - Calling non-transactional method after transaction is rolled back 如何在相同和不同服务中调用@Transactional和non-Transactional方法时回滚事务? - How to rollback transaction on calling @Transactional and non-Transactional method in same and different Service? Spring Boot-从非事务性原因更新中校准事务性方法 - Spring Boot - caling transactional method from non-transactional cause update 是否可以将整个@Transactional类的一个方法标记为非事务性的 - Is it possible to mark one method of an entire @Transactional class as non-transactional 例外-非交易 - Exception - non-transactional 延迟加载在Hibernate的非事务类/方法中工作 - Lazy loading working in non-transactional class/method in Hibernate 从另一个方法调用的@Transactional 方法不获取事务 - @Transactional method called from another method doesn't obtain a transaction 覆盖具有 Spring 的 @transactional 的方法的事务传播级别 - Overriding transaction propagation levels for methods having Spring's @transactional
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM