2010-04-01 55 views
1
  1. 在本例中,是否有任何表元素正在被另一個客戶端更改,或者只有當我們更改的元素已被另一個客戶端更改時,才拋出異常?
  2. 只是爲了驗證 - 從commit()拋出的異常不是嗎?GAE事務異常

    PersistenceManager pm = PMF.get().getPersistenceManager();  
    try { 
        pm.currentTransaction().begin(); 
        List<Row> Table = (List<Row>) pm.newQuery(query).execute(); 
        Table.get(0).setReserved(true); // <----- we change only this element 
        pm.currentTransaction().commit(); 
    } catch (JDOCanRetryException ex) { 
        pm.currentTransaction().rollback() // <----- if Table.get(1) was changed by another client do we get to this point??? 
    } 
    

回答

1

1)例外,將只被拋出如果該實體是在交易過程中的其他地方進行修改。

2.)正確的,當你提交時會拋出異常。

您還必須致電pm.makePersistent(Table.get(0))讓它保存您的更改。

+0

很酷謝謝傑森! – bach 2010-04-02 01:31:16