This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?
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 ]
Joined: Apr 16, 2008
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.