添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

我们正在使用GAE和JDO2.3,有这样的代码。

public void submit_job (HttpSession session, BlobKey blobKey) throws Exception {
  // START TRANSACTION
  PersistenceManager pm = PMF.get().getPersistenceManager();
  Transaction tx = pm.currentTransaction();
  tx.begin();
  // GET JOB AND MEMBER FROM DATASTORE
  Key jobKey = (Key)session.getAttribute("jobkey");
  String userName = session.getAttribute("username").toString();
  Job job = pm.getObjectById(Job.class, jobKey);
  Member m = pm.getObjectById(Member.class, username);
  // STORE JOB INFORMATION IN DATASTORE
  Date now = new Date();
  job.caricature = blobKey;
  job.whenSubmitted = now;
  job.whenFinished = now;
  pm.makePersistent(job);
  pm.flush();
  log.warning("submit_job: updating job " + job.key);
  // UPDATE MEMBER INFORMATION
  m.numSubmittedJobs++;
  pm.makePersistent(m);
  pm.flush();    
  log.warning("submit_job: updating user " + username);
  // COMPLETE TRANSACTION
  tx.commit();
  pm.close();
  log.warning("transaction completed? " + !tx.isActive());
  • 没有抛出异常,一切运行正常
  • 在最后,交易被正确地完成("交易完成?)
  • 下面的查询可以从成员和工作对象中读取更新的数据
  • 该信息没有显示在数据存储管理器中
  • 重启实例后,JDO对象仍有其旧值。所有的变化都丢失了。
  • 这里是我们的jdoconfig.xml。

    <?xml version="1.0" encoding="utf-8"?>
    <jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig">
       <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"/>
           <property name="datanucleus.appengine.datastoreEnableXGTransactions" value="true"/>
       </persistence-manager-factory>
    </jdoconfig>
    

    和persistence.xml。

    <?xml version="1.0" encoding="UTF-8" ?>
    <persistence
        xmlns="http://java.sun.com/xml/ns/persistence"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
        version="1.0">
        <persistence-unit name="transactions-optional">
            <provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
            <properties>
                <property name="datanucleus.NontransactionalRead" value="true"/>
                <property name="datanucleus.NontransactionalWrite" value="true"/>
                <property name="datanucleus.ConnectionURL" value="appengine"/>
            </properties>
        </persistence-unit>
    </persistence>
    

    希望得到任何帮助,我们已经在这个问题上花了很多精力,但是还不能解决这个问题。