aspose file tools*
The moose likes JDBC and the fly likes Continuing a transaction after deadlock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Continuing a transaction after deadlock" Watch "Continuing a transaction after deadlock" New topic
Author

Continuing a transaction after deadlock

Sandhya Narayanan
Greenhorn

Joined: Apr 22, 2007
Posts: 7
I have a transaction which performs multiple database operations - say update1, update2 and update3. The operation update2 is failing occasionally because of a deadlock in Oracle. The exception is as below.

Caused by:
java.sql.BatchUpdateException: ORA-00060: deadlock detected while waiting for resource
ractBatcher.executeBatch(AbstractBatcher.java:242)


I want to catch this exception and retry the update2 operation again if this happens. Will this work or will I have to retry the whole transaction starting from update1 again?

Thanks,
Sandhya
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Are you using the Java Transaction API and hand-written code to manage the transaction?

Which Java application server are you using?

What type of JDBC driver are you using?
Sandhya Narayanan
Greenhorn

Joined: Apr 22, 2007
Posts: 7
No,I'm using declarative transaction handling in Spring using JPATransactionManager. Hibernate is the JPA provider. The application server is WebSphere 6.1. The JDBC driver is Oracle thin driver (type 4)
[ December 13, 2008: Message edited by: Sandhya Narayanan ]
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
If you place the transaction boundaries before update1 and after update 3, you should be able to catch the exception at update 2 and keep trying update2 until it succeeds. The transaction will not fail if you code the exception handling properly. Code something like after three tries and it still had not succeeded, then abort the transaction and rollback whatever update1 did.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Continuing a transaction after deadlock