views:

142

answers:

1

Using JDO on GAE, I'm using a simple database transaction code block like below.

What is a good way to retry/recover from a thrown java.sql.SQLException: Concurrent Modification?

private final Provider pmp; ...

PersistenceManager pm = pmp.get(); try { pm.currentTransaction().begin();

MyObject myObject= pm.getObjectById(MyObject.class, id);

pm.currentTransaction().commit();

} finally {

if (pm.currentTransaction().isActive()) { log.severe( this.getClass().getName() + " caught DATABASE exception."); pm.currentTransaction().rollback(); } }

A: 

Where is that exception actually thrown? Are you sure about the semantics of commit() and isActive()? commit() could automatically create a new transaction leaving the transaction always active.

My other guess would be that this is a singleton bean accessed concurrently and they all end up in the same transaction with other queries concurrently modifying your requested object.

sibidiba
Thanks for suggesting to look more closely at the semantics. Looking more closely at the stack trace and the javadocs.The exception is thrown from the commit() and the java.sql.exception is nested within a javax.jdo.JDODataStoreException which is a subclass of JDOCanRetryExceptionhttp://db.apache.org/jdo/api23/apidocs/javax/jdo/JDODataStoreException.htmlNow is there a way to catch this exception and retry the operation without exporting all the variables into a single parameter block?
Stevko
I still feel this exception should not be thrown. Is your serialization level properly set? Can't your try to commit until currentTransaction().isActive()?
sibidiba