cancel
Showing results for 
Search instead for 
Did you mean: 

JtaTransactionContext and transaction management

mebold
Champ in-the-making
Champ in-the-making
Hi all,

I've used Activiti5.9 till now and I've decided to upgrade to the 5.10 release. In my project I'm using an embedded Activiti ProcessEngine running in osgi environment. To communicate with the database (h2, MySql, MSSQL depending on our configuration) I'm using the transactionmanager provided by the osgi container (ServiceMix 1.2.0). Using the 5.9 version everything worked properly.

When I've changed to the 5.10 version suddenly nothing was inserted into the database. No exceptions, even the transactionManager.commit() function was called while I was debugging it. However, it seemed that no transactions were properly ended, at least nothing was inserted into the database.

After browsing through the release notes I've found this JIRA issue:
http://jira.codehaus.org/browse/ACT-1188

Comparing the changes to the previous version I've seen that the StandaloneMybatisTransactionContextFactory was replaced by the new JtaTransactionContextFactory, reverting this solved the issue. After this I've found that there is a property of the JtaProcessEngineConfiguration: setTransactionExternallyManaged(bool). Since the default value is false I've chaged it to true and having this flag set the to true the new code with the JtaTransactionContextFactory works again.

Though the problem is solved could anyone give me an explanation why and how exactly this should work? How come the commit is called, no exceptions are thrown (eg. SecurityException indicating that commit is not allowed here) if the transactionExternallyManaged is set to false in the activiti configuration?

Thanks, Orsi
2 REPLIES 2

trademak
Star Contributor
Star Contributor
Hi Orsi,

You're right that the JtaProcessEngineConfiguration was changed by resolving JIRA ACT-1188. This change was necessary to have the Activiti transaction context using the JTA transaction instead of the standalone transaction manager. And yes the default value of the transactionsExternallyManaged property is false. For the JtaProcessEngineConfiguration I think this is a bug because from my first thinking the transaction is always externally managed in the JTA configuration. So yes this has to be set to true for now to make this work.
The code that uses this transactionsExternallyManaged property is the following:

protected void initTransactionFactory() {
    if (transactionFactory==null) {
      if (transactionsExternallyManaged) {
        transactionFactory = new ManagedTransactionFactory();
      } else {
        transactionFactory = new JdbcTransactionFactory();
      }
    }
  }

And you need a ManagedTransactionFactory to make the JTA transaction config work.
The reason that you don't get an exception is probably related to the implementation of the JtaTransactionContext class.
If you invoke a commit just nothing happens, it's ignored. Maybe we should add a log message of level warn there to prevent this in the future.
Let me know if you still have questions or remarks.

Best regards,

mebold
Champ in-the-making
Champ in-the-making
Thanks for the explanation.

There is only one small question left: when debugging I can see in the JtaTransactionInterceptor.java class that the
    private void doCommit() {
        try {
            transactionManager.commit();

function is called. That's why I mentioned that theoretically it should be committed. But obviously something is missing here in the transaction management process and noone warns me that what I'm doing is wrong Smiley Happy.

Orsi