Are Transactions Still Not Supported In Jira DC?

Hi.

I’ve investigated a database in a corrupt state. And to my surprise, it seems that there are not transactions with Active Objects in Jira?
So, basically what happens:

  1. I run my code in a ActiveObjects.executeInTransaction().
  2. A few entities are inserted.
  3. Once insert of Entity fails, because a validation error. The request fails with a en exception.
    We do not swallow the exception.
  4. And Surprise, the transaction isn’t rolled back / or is never started. The first few entities where created, but the overall state is now inconsistent.
  5. Now other parts of the App start to fail, because they see a invalid state.

I’ve found multiple references that Jira doesn’t support transaction with Active Objects:

  1. In the Active Objects documentation:

JIRA currently does not support transactions for Active Objects (as of JIRA 6.0).

  1. In this forum: Help with Transaction Support and ActiveObjects in Jira Server

Is this still the case? This is really a ‘bad suprise’ to wake up =(.
This basically should be a big warning sign in the docs about this missing feature.

PS: The work around mentioned this JIRA issue still does work: https://jira.atlassian.com/browse/JRASERVER-25808

2 Likes

Answering myself, but more details welcome.

ActiveObjects executeInTransaction still doesn’t do a transaction, even in new Jira versions. So, it runs the database operations without any transaction. And you will get a nasty surprise if your app fails and you get partial writes.

So, the way to go it still the work around in https://jira.atlassian.com/browse/JRASERVER-25808:

  1. Include the Jira Core dependency:
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-core</artifactId>
            <version>${jira.version}</version>
            <scope>provided</scope>
        </dependency>
  1. Then use the Jira API’s for transactions:
import com.atlassian.jira.transaction.Transaction;
import com.atlassian.jira.transaction.Txn;


    Transaction txn = Txn.begin();
    try {
        // do your database operations.
        txn.commit();
    } finally {
        txn.finallyRollbackIfNotCommitted();
    }
2 Likes

Indeed, this is a nasty wart on the product, I assume most apps are blindly assuming the transaction support in Active Objects works…

1 Like