Wildfly 8.0.0.Final JTA transaction issues

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 10:06:55

问题


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;
}

However, in the case of JTA transaction, we got errors such as:

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

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.

We also tried @Applicationscoped @TransactionalManagement but it does not give us transaction.

What are my options in using Wildfly but not @Stateful or @Statelss @Singleton, etc?


回答1:


Have you tried javax.transaction.Transactional (new in Java EE 7)?

@ApplicationScoped
@Transactional
public MyTransactionalBean {
    // ...
}


来源:https://stackoverflow.com/questions/22163826/wildfly-8-0-0-final-jta-transaction-issues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!