How to keep a UserTransaction through many requests
Issue
- Is it possible keep a UserTransaction through many requests in a CDI/JSF application (WAR)? Below is a simple CDI application deployed on JBoss EAP 6.
- Bean class:
@Named
@ConversationScoped
public class TestBean implements Serializable {
@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());
}
}
- XHTML page:
<!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><br></body>
</html>
- Log output:
Transaction status 0 => ACTIVE
Transaction status 6 => NO_TRANSACTION
16:17:16,474 INFO [org.jboss.tools.examples.controller.TestBean] (http-localhost-127.0.0.1-8080-2) Conversation: 1
16:17:16,476 INFO [org.jboss.tools.examples.controller.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 [org.jboss.tools.examples.controller.TestBean] (http-localhost-127.0.0.1-8080-2) Doing some action...
16:17:19,097 INFO [org.jboss.tools.examples.controller.TestBean] (http-localhost-127.0.0.1-8080-2) Conversation: 1
16:17:19,098 INFO [org.jboss.tools.examples.controller.TestBean] (http-localhost-127.0.0.1-8080-2) Transaction status: 6
-
At that point the transaction should have the status 1 instead of 6.
-
We are getting the below error repeatedly and consistently in our logs :
00:39:06,405 ERROR [org.jboss.as.txn] (ajp-localhost/127.0.0.1:8109-1) JBAS010152: APPLICATION ERROR: transaction still active in request with status 0
Environment
- JBoss Enterprise Application Platform 6
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.