possible bug with JTA transactions
camunda May 7, 2007 8:59 AMHi,
I am not yet sure if it is a bug or a missconfiguration from me. But I am nearly convinced that it is a bug ;-)
I use the JtaDbPersistenceServiceFactory for pesisting (transactionEnabled=true, currentSessionEnabled=true). Now I trigger a process with a small action, which queries process name from jbpm (and therefor create a own jbpmContext). My testcode:
private String testProcess = "<process-definition name='Test'>" + "<start-state name='startState'>" + " <transition name='startTransactionTest' to='end'>" + " <action name='test' class='com.camunda.ccs.process.test.ExecuteJbpmCommand'/>" + " </transition>" + "</start-state>" + "<end-state name='end'/>" + "</process-definition>"; public void testHibernateSession() { // deploy process DeployProcessCommand deployCmd = new DeployProcessCommand(); deployCmd.setXml( testProcess ); Tk4jbpmConfiguration.getCommandService().execute(deployCmd); // now start it StartProcessInstanceCommand cmd = new StartProcessInstanceCommand(); cmd.setProcessName("test"); ProcessInstance pi = (ProcessInstance) Tk4jbpmConfiguration.getCommandService().execute(cmd); // process is ended assertNotNull(pi.getEnd()); }
(The Tk4jbpmConfiguration.getCommandService() just gets a reference to a EJB-3-ServiceBean, which runs the execute in TransactionAttributeType.REQUIRED).
The aciton is very easy:
public class ExecuteJbpmCommand implements ActionHandler { public void execute(ExecutionContext ctx) throws Exception { GetProcessDefinitionCommand cmd = new GetProcessDefinitionCommand(); Tk4jbpmConfiguration.getCommandService().execute(cmd); } }
Now I get the following problem: The first context starts a transaction (and gets the current user transaction from hibrnate). The second jbpmContext get the same transaction. But it commits & closes it at the end (the commit has of xourse no effect on the JTA-Transaction, but the begun marker of the hibernate JTATransaction is set to false!). After that, we get a Exception while closing the JTATransaction the second time. If we ignore it, everything seems to work fine.
You can also see that in the logs:
DEBUG [org.jbpm.JbpmContext] creating org.jbpm.JbpmContext@27e905
DEBUG [com.camunda.toolkit.jbpm.service.CommandServiceBean] executing org.jbpm.command.StartProcessInstanceCommand@336f59...
DEBUG [org.jbpm.persistence.db.DbPersistenceService] using current hibernate session SessionImpl(...)
DEBUG [org.jbpm.persistence.db.DbPersistenceService] beginning hibernate transaction
DEBUG [org.hibernate.transaction.JTATransaction] Looking for UserTransaction under: UserTransaction
DEBUG [org.hibernate.transaction.JTATransaction] Obtained UserTransaction
DEBUG [org.hibernate.transaction.JTATransaction] begin
DEBUG [org.jbpm.persistence.db.DbPersistenceService] begun hibernate transaction org.hibernate.transaction.JTATransaction@d34b8c
DEBUG [org.jbpm.configuration.JbpmContextInfo] creating jbpm context with service factories '[message, tx, scheduler, authentication, persistence, logging]'
DEBUG [org.jbpm.JbpmContext] creating org.jbpm.JbpmContext@12f2476
DEBUG [com.camunda.toolkit.jbpm.service.CommandServiceBean] executing org.jbpm.command.GetProcessDefinitionCommand@2fe28...
DEBUG [org.jbpm.persistence.db.DbPersistenceService] using current hibernate session SessionImpl(...)
DEBUG [org.jbpm.persistence.db.DbPersistenceService] beginning hibernate transaction
DEBUG [org.jbpm.persistence.db.DbPersistenceService] begun hibernate transaction org.hibernate.transaction.JTATransaction@d34b8c
DEBUG [com.camunda.toolkit.jbpm.service.CommandServiceBean] ... finished with org.jbpm.command.GetProcessDefinitionCommand@2fe28
DEBUG [org.jbpm.JbpmContext] closing org.jbpm.JbpmContext@12f2476
DEBUG [org.jbpm.svc.Services] closing service 'persistence': org.jbpm.persistence.jta.JtaDbPersistenceService@1d6c90d
DEBUG [org.jbpm.persistence.db.DbPersistenceService] committing hibernate transaction org.hibernate.transaction.JTATransaction@d34b8c
DEBUG [org.hibernate.transaction.JTATransaction] commit
DEBUG [com.camunda.toolkit.jbpm.service.CommandServiceBean] ... finished with org.jbpm.command.StartProcessInstanceCommand@336f59
DEBUG [org.jbpm.JbpmContext] closing org.jbpm.JbpmContext@27e905
DEBUG [org.jbpm.svc.Services] closing service 'persistence': org.jbpm.persistence.jta.JtaDbPersistenceService@383c13
DEBUG [org.jbpm.persistence.db.DbPersistenceService] committing hibernate transaction org.hibernate.transaction.JTATransaction@d34b8c
ERROR [org.jbpm.persistence.db.DbPersistenceService] hibernate commit failed
org.hibernate.TransactionException: Transaction not successfully started
at org.hibernate.transaction.JTATransaction.commit(JTATransaction.java:126)
at org.jbpm.persistence.db.DbPersistenceService.commit(DbPersistenceService.java:255)
at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:213)
at org.jbpm.persistence.jta.JtaDbPersistenceService.close(JtaDbPersistenceService.java:34)
at org.jbpm.svc.Services.close(Services.java:222)
at org.jbpm.JbpmContext.close(JbpmContext.java:139)
at com.camunda.toolkit.jbpm.service.CommandServiceBean.execute(CommandServiceBean.java:91)
Now, what is the right way to handle it? I am not completly sure at this point...
Any remarks?