我正在使用 SQLServer
和 Springs JtaTransactionManager
。
给出这样的方法:
@Transactional
public void something() {
try (final Connection conn1 = getConnection()) {
//insert/update stuff in database
}
try (final Connection conn2 = getConnection()) {
//insert/update stuff in database
}
}
这个方法实际上是事务性的吗?当 conn1
关闭时所做的更改会发生什么,它们是否已提交到数据库?如果在使用 conn2
时发生异常,会发生什么情况,通过关闭的连接所做的更改是否可以回滚?
最佳答案
您不应在 @Transactional
内手动加载/获取连接或数据源,尤其是在使用 JtaTransactionManager 时
The JtaTransactionManager does not need to know about the DataSource, or any other specific resources, because it uses the container’s global transaction management infrastructure.
关于java - 当连接在事务中关闭时会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59408397/