Wildfly 8.0.0.Final JTA交易问题 [英] Wildfly 8.0.0.Final JTA transaction issues
问题描述
由于我们在事务中使用了很多@ApplicationScoped bean但我们不想使用EJB(ApplicationScoped bean不能与无状态bean一起使用),我们创建了自己的事务拦截器,例如:
Since we use a lot of @ApplicationScoped beans with transaction but we do not want to use EJBs (ApplicationScoped bean does not work with stateless beans), we create our own transaction interceptor such as:
@Resource
UserTransaction tx;
@Resource(mappedName="java:jboss/TransactionSynchronizationRegistry")
TransactionSynchronizationRegistry tsr;
@AroundInvoke
public Object manageTransaction(InvocationContext context) throws Exception {
Object result;
if (Status.STATUS_NO_TRANSACTION == tsr.getTransactionStatus()) {
tx.begin();
// System.out.println("Starting transaction");
result = context.proceed();
tx.commit();
} else {
result = context.proceed();
}
// System.out.println("Committing transaction");
return result;
}
但是,在JTA交易的情况下,我们遇到如下错误:
However, in the case of JTA transaction, we got errors such as:
使用自己的TransactionInterceptor导致
引起:java.sql.SQLException:java.sql.SQLException:XAER_RMFAIL:The当全局事务处于IDLE状态时,命令无法执行
Using own TransactionInterceptor caused
Caused by: java.sql.SQLException: java.sql.SQLException: XAER_RMFAIL: The command cannot be executed when global transaction is in the IDLE state
我们曾经使用Seam3托管事务,它似乎工作正常。但它不再适用于Wildfly。我们尝试了Deltaspike的jpa模块,但是看起来围绕多个数据源的事务有问题(非JTA似乎很好),即使我们按照他们的指示。
We used to use Seam3 managed transaction and it seems working fine. But it does not work in Wildfly anymore. We tried Deltaspike's jpa module, but it seems having problems with transaction around multiple datasources (non-JTA seems fine) even we followed their instruction.
我们也试过@Applicationscoped @ TransactionalManagement但它没有给我们交易。
We also tried @Applicationscoped @TransactionalManagement but it does not give us transaction.
我使用Wildfly但有没有@Stateful或@Statelss @Singleton等有什么选择?
What are my options in using Wildfly but not @Stateful or @Statelss @Singleton, etc?
推荐答案
您是否尝试过 javax.transaction.Transactional
(Java EE 7中的新增内容)?
Have you tried javax.transaction.Transactional
(new in Java EE 7)?
@ApplicationScoped
@Transactional
public MyTransactionalBean {
// ...
}
这篇关于Wildfly 8.0.0.Final JTA交易问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!