0

I am using JDO (3.x, with datanucleus 2) to persist objects in one of my apps in the google app engine (java). My sequence of calls are such:

  1. Open persistence manager in servlet filter (servlet 1) - Using ThreadLocal

  2. call pm.findByObjectId from DAO class (via servlet 1)

  3. call pm.deletePersistent from DAO class (via servlet 1)

  4. call pm.newQuery to list all objects now in db (via servlet 1) - write to response (json)

  5. Close persistence manager in servlet filter - inside finally of doFilter method

However, my objects are not being deleted until I close the pm in step 5. Also it is not consitent, sometimes it does get deleted !(havent figured out when). I would ideally want the objects to be deleted in Step 3 above, so that when in step 4 my query runs, it returns the updated list.

Could anyone please let me know if I could improve on this design to do inserts/deletes more atomically that this. Or is it just because the writes to the database are too slow ?

Here's my jdoconfig.xml

<persistence-manager-factory name="transactions-optional"> <property name="javax.jdo.PersistenceManagerFactoryClass" value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory"/> <property name="javax.jdo.option.ConnectionURL" value="appengine"/> <property name="javax.jdo.option.NontransactionalRead" value="true"/> <property name="javax.jdo.option.NontransactionalWrite" value="true"/> <property name="javax.jdo.option.RetainValues" value="true"/> <property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/> <property name="datanucleus.appengine.singletonPMFForName" value="true"/> </persistence-manager-factory>

4

1 回答 1

0

我怀疑您的 GAE 环境设置为关闭时提交。您可以使用 JDO API 控制事务边界,例如:

Transaction jdoTx = pm.currentTransaction();
jdoTx.begin();
pm.deletePersistent(obj);
jdoTx.commit();
于 2013-10-02T22:39:26.220 回答