开发者

how to retry/recover from a java.sql.SQLexception: Concurrent Modification

开发者 https://www.devze.com 2022-12-18 17:27 出处:网络
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: Concurre开发者_StackOverflow中文版nt Modific

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: Concurre开发者_StackOverflow中文版nt 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(); } }


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消