事务不回滚

发布于 2024-11-16 13:48:38 字数 654 浏览 4 评论 0原文

我在 Fuse (OSGi) 中部署了 mybatis 3.0.4 和 mybatis-spring 集成 1.0.1。我在 SQLServer 2008 中创建了一个基本数据库。在 Spring 中,我配置了一个 TransactionAwareDataSourceProxy 数据源和一个 DataSourceTransactionManager 事务管理器。

现在我已经创建了自己的包,要在 Fuse 中部署,它将一些行插入数据库。我已经告诉捆绑包使用配置的数据源和事务管理器。执行逻辑的方法如下所示:

@Transactional(propagation=Propagation.REQUIRED)
public void go(RecsCashContext context) throws ActionException {

当该方法抛出异常时,我可以通过查看触发的预期行为来跟踪 Spring。这将我引向 Springs JtaTransactionManagerdoRollBack(..)

所以一切看起来都很有希望,除了当我查看数据库时,果然它处于不稳定状态,因为以前的插入尚未回滚。

我对此一无所知,并且正在努力在网上寻找任何信息。有什么想法吗?

I have mybatis 3.0.4 with mybatis-spring integration 1.0.1 deployed within Fuse (OSGi). I've created a basic database within SQLServer 2008. In Spring I've configured a TransactionAwareDataSourceProxy data source and a DataSourceTransactionManager transaction manager.

Now I've created my own bundle to be deployed within Fuse which inserts some rows into the database. I've told the bundle to use the configured data source and transaction manager. The method which carries out the logic looks like this:

@Transactional(propagation=Propagation.REQUIRED)
public void go(RecsCashContext context) throws ActionException {

When this method throws an exception I can follow Spring through seeing the expected behaviour triggered. This leads me to Springs JtaTransactionManager and doRollBack(..).

So everything looks promising, except that when I look at the database, sure enough it's in an unstable state as previous inserts have not been roll back.

I'm at a loss on this one and I'm struggling to find any information online. Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遗弃M 2024-11-23 13:48:38

抛出什么样的异常?除非你告诉 Spring 在抛出特定异常时显式回滚,否则它将继续进行。默认情况下,Spring 的事务处理仅在抛出未经检查的异常(例如 RuntimeException)时回滚。在您的情况下,如果您期望在 ActionException 发生时发生回滚,那么除非您进行以下修改,否则您就不走运:

@Transactional(rollbackFor={ActionException.class})
public void go(RecsCashContext context) throws ActionException {

更多详细信息位于 此处,特别是在第 10.5.6.1 节,@Transactional 设置中

What kind of exception is being thrown? Unless you tell Spring to explicitly rollback when a particular exception is thrown, it will proceed. By default, Spring's transaction handling only rolls back when an unchecked exception (e.g. RuntimeException) is thrown. In your case, if you're expecting the rollback to occur when ActionException occurs, you're out of luck unless you make the following modification:

@Transactional(rollbackFor={ActionException.class})
public void go(RecsCashContext context) throws ActionException {

More details are in here, specifically in section 10.5.6.1, @Transactional settings

瘫痪情歌 2024-11-23 13:48:38

事实证明,Fuse (servicemix) 已经通过捆绑包 org.apache.aries.transaction.manager_0.2.0.incubating [49] 中的 OSGi 服务公开了事务管理器。结果,当我查找事务管理器服务时,第一个找到的是捆绑包 49 公开的服务。

通过明确指定我感兴趣的事务管理器可以解决这个问题。目前我正在使用 bean-name 属性来执行此操作:

<osgi:reference id="transactionManager" bean-name="transactionManager" interface="org.springframework.transaction.PlatformTransactionManager" />

虽然这也可以通过使用过滤器来完成,但最好我们只使用事务经理服务已经公开,而不是提供我们自己的服务。

As it turns out Fuse (servicemix) already exposes a transaction manager via an OSGi service within bundle org.apache.aries.transaction.manager_0.2.0.incubating [49]. As a result when I was looking up the transaction manager service, the one exposed by bundle 49 got picked up first.

This was resolved by clearly specifying the transaction manager I was interested in. At the moment I am doing this using the bean-name propery:

<osgi:reference id="transactionManager" bean-name="transactionManager" interface="org.springframework.transaction.PlatformTransactionManager" />

Though this could also be done by using a filter, but preferably we'll just make use of the transaction manager service that's already being expose as opposed to providing our own.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文