kellyfj
kellyfj

Reputation: 6983

JTA Transaction: What happens if an exception happens but rollback is not called on the transaction?

We have some third party code wherein they do the following

  1. List item

    Create a User Transaction e.g.

     txn = (UserTransaction)ctx.lookup( "UserTransaction" );
     txn.begin(  );
    
  2. Do some work persisting to the database (via JPA) to a MySQL database

  3. txn.commit()

They have Exception blocks but NONE of them call txn.rollback. Good coding practice says they NEED to call rollback if an exception occurs but my question is If the txn is not committed, and an exception occurs what is the negative effect of them NOT calling rollback?

Upvotes: 0

Views: 1363

Answers (2)

Anuj Kaushal
Anuj Kaushal

Reputation: 61

IMO the JTA transaction should eventually timeout (based on the set or default transactionTimeout) and should automatically rollback.

Upvotes: 1

Bozho
Bozho

Reputation: 597432

The transaction stays active, until you either commit() or rollback() it. It will continue to hold locks and you may end up blocking your application (database, actually).

Upvotes: 4

Related Questions