事务提交抛出异常:事务设置为仅回滚

Posted

技术标签:

【中文标题】事务提交抛出异常:事务设置为仅回滚【英文标题】:Transaction commit throwing exception: Transaction set to rollback only 【发布时间】:2012-03-26 16:20:42 【问题描述】:

我的应用程序试图在 DB2 服务器上的 2 个数据库上执行分布式事务,应用程序服务器是 websphere 6.1,并使用 Atomikos 作为 TM。

UserTranaction.commit() 失败,出现以下异常: javax.transaction.RollbackException:事务设置为仅回滚 完整的堆栈跟踪是:

    [3/26/12 12:08:43:880 EDT] 0000001f SystemErr     R javax.transaction.RollbackException: Transaction set to rollback only
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.atomikos.icatch.jta.TransactionImp.rethrowAsJtaRollbackException(TransactionImp.java:70)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.atomikos.icatch.jta.TransactionImp.commit(TransactionImp.java:250)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.atomikos.icatch.jta.TransactionManagerImp.commit(TransactionManagerImp.java:498)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.atomikos.icatch.jta.UserTransactionImp.commit(UserTransactionImp.java:129)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.Servlet.InitialServlet.doPost(InitialServlet.java:131)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1101)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:569)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3440)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:267)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:815)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1461)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:118)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:458)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:387)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:102)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:195)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:743)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:873)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1473)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R Caused by: com.atomikos.icatch.RollbackException: Transaction set to rollback only
    at com.atomikos.icatch.imp.TxRollbackOnlyStateHandler.commit(TxRollbackOnlyStateHandler.java:84)
    at com.atomikos.icatch.imp.CompositeTransactionImp.doCommit(CompositeTransactionImp.java:319)
    at com.atomikos.icatch.imp.CompositeTerminatorImp.commit(CompositeTerminatorImp.java:79)
    at com.atomikos.icatch.jta.TransactionImp.commit(TransactionImp.java:236)
    at com.atomikos.icatch.jta.TransactionManagerImp.commit(TransactionManagerImp.java:498)
    at com.atomikos.icatch.jta.UserTransactionImp.commit(UserTransactionImp.java:129)
    at com.Servlet.InitialServlet.doPost(InitialServlet.java:131)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1101)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:569)
    at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
    at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3440)
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:267)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:815)
    at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1461)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:118)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:458)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:387)
    at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:102)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:195)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:743)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:873)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1473)

[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.atomikos.icatch.imp.TxRollbackOnlyStateHandler.commit(TxRollbackOnlyStateHandler.java:84)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.atomikos.icatch.imp.CompositeTransactionImp.doCommit(CompositeTransactionImp.java:319)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.atomikos.icatch.imp.CompositeTerminatorImp.commit(CompositeTerminatorImp.java:79)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     at com.atomikos.icatch.jta.TransactionImp.commit(TransactionImp.java:236)
[3/26/12 12:08:43:896 EDT] 0000001f SystemErr     R     ... 24 more

我没有将事务设置为仅在代码中回滚。我猜它是默认设置的。我想更改它而不是将其设置为 rollbackOnly。另外,我在事务之后明确调用 commit() 。为什么我仍然收到此异常?我如何确保事务被提交?

【问题讨论】:

【参考方案1】:

解决了这个问题!! 这对我有用:

    打开 Web 部署描述符 选择启动事务的 Servlet。 对于 Servlet,选择 Websphere Extensions > Local Transaction。 将解析器设置为“ContainerAtBoundary”和未解析的操作:回滚。 保存并重新发布。

瞧……我现在可以提交交易了!!

【讨论】:

以上是关于事务提交抛出异常:事务设置为仅回滚的主要内容,如果未能解决你的问题,请参考以下文章

JFinal 数据库“手动”事务(提交回滚)

如果在提交时抛出异常,C# TransactionScope 会回滚吗?

事务场景中,抛出异常被catch后,如果需要回滚,一定要手动回滚事务

spring自己抛出异常,居然不能回滚

(转)spring异常抛出触发事务回滚策略

spring配置了事务,抛出异常不回滚