java Arjuna JTA 事务意外回滚

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9925676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 22:55:38  来源:igfitidea点击:

Arjuna JTA transaction rollbacked unexpectedly

javatransactionsjbossjms

提问by Olivier.Roger

When I check JBoss logs I see a lots of those errors

当我检查 JBoss 日志时,我看到了很多这样的错误

2012-03-29 12:01:27,358 WARN  @ [com.arjuna.ats.jta.logging.loggerI18N] [com.arjuna.ats.internal.jta.resources.arjunacore.norecoveryxa] [com.arjuna.ats.internal.jta.resources.arjunacore.norecoveryxa] Could not find new XAResource to use for recovering non-serializable XAResource < 131075, 32, 30, 1--53e2af7c:eff6:4ec11bf7:2e1da4-53e2af7c:eff6:4ec11bf7:2e263d                                                                   >
2012-03-29 12:01:27,398 WARN  @ [com.arjuna.ats.jta.logging.loggerI18N] [com.arjuna.ats.internal.jta.resources.arjunacore.norecoveryxa] [com.arjuna.ats.internal.jta.resources.arjunacore.norecoveryxa] Could not find new XAResource to use for recovering non-serializable XAResource < 131075, 31, 29, 1--53e2af7c:d397:4e8c1b0e:25b6d-53e2af7c:d397:4e8c1b0e:29d09                                                                     >

Then, when I try to send a JMS message I see this error:

然后,当我尝试发送 JMS 消息时,我看到此错误:

2012-03-29 12:02:43,778 WARN  @ [com.arjuna.ats.jta.logging.loggerI18N] [com.arjuna.ats.internal.jta.resources.arjunacore.opcerror] [com.arjuna.ats.internal.jta.resources.arjunacore.opcerror] XAResourceRecord.commit_one_phase caught: java.lang.IllegalMonitorStateException
2012-03-29 12:02:43,778 WARN  @ [org.springframework.jms.listener.DefaultMessageListenerContainer] Setup of JMS message listener invoker failed for destination 'queue/request' - trying to recover. Cause: JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is javax.transaction.RollbackException: [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] Can't commit because the transaction is in aborted state

I suspect the rollback to be a consequence of the previous error. Am I right ? what could cause the transaction to remain in an aborted state like this ?

我怀疑回滚是上一个错误的结果。我对吗 ?什么会导致事务像这样保持中止状态?

looking around I found this post : What causes Arjuna 1603 (Could not find new XAResource to use for recovering non-serializable XAResource). I understand that some log of transaction have been kept but this does not explains how to fix the issue I now have.

环顾四周,我发现了这篇文章:什么原因导致 Arjuna 1603 (Could not find new XAResource to use for recovery non-serializable XAResource)。我知道一些交易日志已被保留,但这并没有解释如何解决我现在遇到的问题。

回答by drone.ah

I have seen similar errors on JBoss 5.1 (at least the second one which refers to a timeout)

我在 JBoss 5.1 上看到过类似的错误(至少第二个是指超时)

We did not find the actual cause but it is highly likely that it is caused due to a long running transaction that gets "reaped"

我们没有找到真正的原因,但很可能是由于长时间运行的事务被“收割”造成的

The reason we came to this conclusion is that we saw this at times of high load and some operations were taking a long time to complete.

我们得出这个结论的原因是我们在高负载时看到了这一点,并且一些操作需要很长时间才能完成。

We use PostgreSQL and there were a lot of connections "waiting in transaction" which get cleared after the reaping. Check the transaction timeout in your configuration and set it to higher value to see if it alleviates the problem.

我们使用 PostgreSQL 并且有很多连接“在事务中等待”在收获后被清除。检查配置中的事务超时并将其设置为更高的值以查看它是否可以缓解问题。

https://community.jboss.org/wiki/TransactionTimeoutcovers how to manage this setting.

https://community.jboss.org/wiki/TransactionTimeout介绍了如何管理此设置。

回答by Doron Manor

In general, every RuntimeException that gets thrown from a managed been (something injected that is wrapped with a JBoss proxy) and that is not marked as an @ApplicationException(rollback = false) will cause the transaction to rollback.

通常,从托管的 be 抛出的每个 RuntimeException(用 JBoss 代理包装的注入的东西)并且没有标记为 @ApplicationException(rollback = false) 将导致事务回滚。

These cases are usually very easy to see in the log files.

这些情况通常很容易在日志文件中看到。

Timeouts on the other hand, are a bit trickier. you will see in the log file something like: "Abort of action id -3f57fd2d:e48e:4cf8de0f:bc invoked while multiple threads active within it."

另一方面,超时有点棘手。您将在日志文件中看到类似于:“中止操作 id -3f57fd2d:e48e:4cf8de0f:bc 在其中多个线程处于活动状态时调用。”

Other calls will continue to run and will fail only when they try to access the database connection, receiving the "transaction is marked for rollback" exception.

其他调用将继续运行,只有在尝试访问数据库连接时才会失败,收到“事务已标记为回滚”异常。

回答by Alex Schultz

We were receiving a similar error and later found out that the cause had to do with how we were creating and handling our entities. We had a parent object with a list of children entities and we were creating copies of the parents and then trying to add new children to the lists. The problem though was that those child lists were marked with the lazy loading annotation:

我们收到了类似的错误,后来发现原因与我们创建和处理实体的方式有关。我们有一个带有子实体列表的父对象,我们正在创建父对象的副本,然后尝试将新子对象添加到列表中。但问题是那些子列表被标记为延迟加载注释:

@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY ...

@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY ...

which was causing hibernate to fail. To fix it we had call evict on the entity so that Hibernate would stop trying to fetch the children whenever we created copies of the parent.

这导致休眠失败。为了解决这个问题,我们在实体上调用了 evict,这样每当我们创建父级的副本时,Hibernate 就会停止尝试获取子级。

((Session) entityManager.getDelegate()).evict(entity to evict)

((Session) entityManager.getDelegate()).evict(entity to evict)

This may not be the solution to your particular problem, but hopefully it helps someone!

这可能不是您特定问题的解决方案,但希望它可以帮助某人!

回答by user3838497

We solve the issue increasing max_prepared_transactions to 100 in postgresql.conf file.

我们解决了在 postgresql.conf 文件中将 max_prepared_transactions 增加到 100 的问题。