podagation.requires_new在JDBC级别上工作?
我已经阅读了文档,并且了解了传播的方式。requires_new有效,但
Create a new transaction, and suspend the current transaction if one exists. Analogous to the EJB transaction attribute of the same name.
NOTE: Actual transaction suspension will not work out-of-the-box on all transaction managers. This in particular applies to org.springframework.transaction.jta.JtaTransactionManager, which requires the javax.transaction.TransactionManager to be made available to it (which is server-specific in standard Java EE).
See Also:
org.springframework.transaction.jta.JtaTransactionManager.setTransactionManager
我不明白暂停如何工作。
对于单级事务,我想Spring会创建这样的代码:
Connection connection = DriverManager.getConnection(...);
try {
connection.setAutoCommit(false);
PreparedStatement firstStatement = connection.prepareStatement(...);
firstStatement.executeUpdate();
PreparedStatement secondStatement = connection.prepareStatement(...);
secondStatement.executeUpdate();
connection.commit();
} catch (Exception e) {
connection.rollback();
}
您能为 propagation.requires_new
提供一个示例吗?
它是否通过JDBC保存点以某种方式完成?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
大多不是。
JDBC不支持暂停交易的概念(它支持了子交易的概念,但是 - 这就是SavePoint的意义。JDBC确实如此,也就是说 - 许多DB发动机都没有)。
那么 它如何工作?
通过超越JDBC的范围。数据库需要支持它,和驱动程序还需要在JDBC API之外进行支持。因此,通过基于非JDBC的DB交互模型或发送SQL命令。
例如,在WebLogic中,有。这不是开源的,所以我不知道它是如何工作的,但是它是单独的API(不是JDBC)的事实。
这也说,
jtatransactionManager
的Javadoc说,只有2个已知的实现,并且这些实现非常接近JTA中的定义。直接从那个Javadoc:
所以,jndi。确实,“ Voodoo跳过JDBC直接与数据库魔术交谈”。
It mostly doesn't.
JDBC doesn't support the notion of suspending transactions (it supports the notion of subtransactions, though - that's what savepoints are about. JDBC does, that is - many DB engines do not).
So how does it work?
By moving beyond the confines of JDBC. The database needs to support it, and the driver also needs to support it, outside of the JDBC API. So, via a non-JDBC-based DB interaction model, or by sending an SQL command.
For example, In WebLogic, there's the WebLogic TransactionManager. That's not open source, so I have no idea how it works, but the fact that it's a separate API (not JDBC) is rather telling.
It's also telling that the javadoc of
JtaTransactionManager
says that there are only 2 known implementations, and that these implementations steer quite close to the definitions in JTA.Straight from that javadoc:
So, JNDI then. "Voodoo skip JDBC talk directly to the database magic" indeed.