Keep a UserTransaction through many requests
ronaldocwb May 21, 2012 3:27 PMHi,
I need to keep a UserTransaction through many requests in a CDI/JSF application (WAR). I have tried many ways but i can't attach my transaction to my conversational bean. See the example below:
It's a simple CDI application deployed on JBossAS 7.1.
My Bean:
@Named
@ConversationScoped
public class TestBean implements Serializable {
          private static final long serialVersionUID = 759936979473538251L;
  
          @Inject
          private UserTransaction userTransaction;
  
          @Inject
          Conversation conversation;
  
          protected Logger log = Logger.getLogger(TestBean.class);
  
          public void begin() throws Exception{
                    conversation.begin();
                    try {
                              userTransaction.begin();
                    } catch (Exception e) {
                              e.printStackTrace();
                    }
                    logStatus();
          }
  
          public void doSomeAction() throws Exception{
                    log.info("Doing some action...");
                    logStatus();
          }
  
          private void logStatus() throws Exception {
                    log.info("Conversation: " + conversation.getId());
                    log.info("Transaction status: " + userTransaction.getStatus());
          }
}
My XHTML file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"> 
<h:head></h:head> 
<body>
    <h:form>
              <h:commandButton action="#{testBean.begin()}" value="Begin" />
              <h:commandButton action="#{testBean.doSomeAction()}" value="Do some action!" />
    </h:form>
</body> 
</html>
Log output:
Transaction status 0 => ACTIVE
Transaction status 6 => NO_TRANSACTION
16:17:16,474 INFO [br.com.veere.bean.TestBean] (http-localhost-127.0.0.1-8080-2) Conversation: 1 16:17:16,476 INFO [br.com.veere.bean.TestBean] (http-localhost-127.0.0.1-8080-2) Transaction status: 0 16:17:16,485 ERROR [org.jboss.as.txn] (http-localhost-127.0.0.1-8080-2) JBAS010152: APPLICATION ERROR: transaction still active in request with status 0 16:17:19,096 INFO [br.com.veere.bean.TestBean] (http-localhost-127.0.0.1-8080-2) Doing some action... 16:17:19,097 INFO [br.com.veere.bean.TestBean] (http-localhost-127.0.0.1-8080-2) Conversation: 1 16:17:19,098 INFO [br.com.veere.bean.TestBean] (http-localhost-127.0.0.1-8080-2) Transaction status: 6
At the point that transaction have the status 6 I needed to continue the same transaction that I started.
I've serched by this error (JBAS010152) but I didn't get any solution.
Sample eclipse project and war file attached.
Is there any solution to this case?
- 
            
                            
            UserTransactionJB7.war 4.4 KB
- 
            
                            
            UserTransactionJB7.zip 9.3 KB
