Reputation: 6983
We have some third party code wherein they do the following
List item
Create a User Transaction e.g.
txn = (UserTransaction)ctx.lookup( "UserTransaction" );
txn.begin( );
Do some work persisting to the database (via JPA) to a MySQL database
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
Reputation: 61
IMO the JTA transaction should eventually timeout (based on the set or default transactionTimeout) and should automatically rollback.
Upvotes: 1
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