[英]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.